例題:請撰寫函式fun,其功能是:將str所指字串中下標為偶數同時ASCII值為奇數的字符洗掉,str中剩余的字符形成的新串放在s所指的陣列中,
例如,若str所指字串中的內容為ABCDEFG12345,其中字符C的ASCII碼值為奇數,在陣列中的下標為偶數,因此必須洗掉;而字符1的ASCII碼值為奇數,在陣列中的下標也為奇數,因此不應當洗掉,其它以此類推,最后s所指的陣列中的內容應是BDF12345,
請勿改動主函式main與其它函式中的任何內容,僅在函式fun的花括號中填入所撰寫的若干陳述句,
代碼如下:
#include<conio.h>
#include<stdio.h>
#include<string.h>
void fun(char*str,char s[])
{
int i,j=0,n=strlen(str);
for(i=0;i<n;i++)
if(i%2==0&&str[i]%2!=0);
else
{
s[j]=str[i];
j++;
}
s[j]='\0';
}
main()
{
char str[100],s[100];
FILE*out;
printf("\nPlease enter string:");
scanf("%s",str);
fun(str,s);
printf("\nThe result is:%s\n",s);
out=fopen("outfile.dat","w");
strcpy(str,"Please enter string:");
fun(str,s);
fprintf(out,"%s",s);
fclose(out);
}
輸出運行視窗如下:

越努力越幸運!
加油,奧力給!!!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/243541.html
標籤:其他
上一篇:2020年年終總結_By 吾方羨
下一篇:程式員,請您不要老是熬夜
