请编写函数fun(),其功能是:将s所指字符串中下标为奇数的字符删除,串中剩余字符形成的新串放在t所

17 查阅

请编写函数fun(),其功能是:将s所指字符串中下标为奇数的字符删除,串中剩余字符形成的新串放在t所指数组中。

例如,当s所指字符串中的内容为siegAHdied,则在t所指数组中的内容应是seAde。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:

include<conio.h>

include<stdio.h>

include<string.h>

void fun(char*S,char t[])

{

}

main()

{

char s[100],t[100];

clrscr();

printf("\nPlease enter string s:");

scanf("%S",S);

fun(S,t);

printf("\nThe result is:%s\n",t);

}

参考答案:

void fun (char *Schar t[]) { int ij=0k=strlen(s); /*k为字符串的长度*/ for(i=0;ik;i=i+2) /*将s所指字符串中下标为偶数的字符存入t所指字符串中*/ t[j++]=s[i]; t[j]='\0'; /*在字符串最后加上结束标志*/ }void fun (char *S

计算机二级