例題:給定程式的功能是判斷字串s中的某個字符是否與字符ch相同,若相同什么也不做,若不同則插在字串的最后,
例如,輸入test,如果輸入e,輸出的結果不變,但如果輸入a,結果testa,
請勿改動主函式main與其它函式中的任何內容,僅在函式fun的花括號中填入所撰寫的若干陳述句,
代碼如下:
#include<stdio.h>
#include<string.h>
void fun(char*s,char ch)
{
while(*s&&*s!=ch)
s++;
if(*s!=ch)
{
s[0]=ch;
s[1]=0;
}
}
main()
{
char str[81],c;
printf("\nPlease input a string:\n");
gets(str);
printf("\n Please enter the character to search:");
c=getchar();
fun(str,c);
printf("\nThe result is %s\n",str);
}
輸出運行視窗如下:


越努力越幸運!
加油,奧力給!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/241330.html
標籤:其他
上一篇:2021考研結束啦
