问题
多项选择题
函数fun的功能是:将s所指字符串中下标为偶数同时ASCII值为奇数的字符删除,s所指串中剩余的字符形成的新串放在t所指的数组中。
注意:部分源程序给出如下。
请勿改动mam函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include <stdio.h>
#include <string.h>
void fun(char *s, char t[])
main()
char s[100], t[100];
printf("\nPlease enter string S:");
scanf("%s", s);
fun(s, t);
printf("\nThe result is:%s\n", t);
答案
参考答案:void fun (char *s, char t[])
{
inti, j=0;
for(i=0; i<strlen(s); i++)
if(!((i%B)==0&&(s[i]%B)))
t[j++]=s[i];
t[j]=0;
}
解析: 使用循环遍历字符串,将下标和ASCII码值满足要求的元素赋给新的字符串。