函数fun的功能是:将s所指字符串中ASCI值为偶数的
函数fun的功能是:将s所指字符串中ASCI值为偶数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为:“ABCDEFG12345”,其中字符B的ASCII码值为偶数、…、字符2的ASCII码值为偶数、...都应当删除,其它依此类推。最后t所指的数组中的内容应是:“ACEG135”。
注意:部分源程序存在文件PROG1.c中。
请勿改动主函数mam和其它函数中的任何内容。
答案
#include <stdio.h>
#include <string.h>
void fun(char *s,char t[])
{
int i=0;
for(;*s!='\0';s++)
if(*s%2==1)
t[i++]=*s;
t[i]='\0';
}
void main()
{
char s[100],t[100];
printf("\nPlease enter string S:");
scanf("%s",s);
fun(s,t);
printf("\nThe result is: %s\n", t);
}