填空题 下列给定程序中,函数fun的功能是:依次取出字符串中所有的数字字符,形成新的字符串,并取代原字符串。
请改正程序中的锴误,使它能得出正确的结果。
注意 :不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib,h>
#include<stdio.h>
#include<conio.h>
void fun(char *s)
{
int i,j;
for(i=0,j=0;s[i]!="/0";i++)
if(s[i]>="0"&&s[i]<="9")
/********found********/
s[j]=s[i];
/********found********/
s[j]="/0";
}
void main()
{
char item[80];
system("CL5");
printf("/nEnter a string:");
gets(item);
printf("/n/nThe string is:%s/n",item);
fun(item);
printf("/n/nThe string of changing is:%s/n",item);
}
【正确答案】
【答案解析】s[j++]=s[i]; s[j]= "/0";[解析] 题目要求依次取出字符串中所有的数字字符,因此将元素s[i]存入s[j]后要使j加1,为下次存储做准备。s[j]="/0";是一个语法错误。