题目内容:
下列给定程序中,函数proc()的功能是:依次取出字符串中所有的数字字符,形成新的字符串,并取代原字符串。例如原始字符串是“ab45c6djfd789”,则输出后的字符是“456789”。
请修改函数proc()中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>-
void proc(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 str[80];
system("CLS"):
printf("\nEnter a string:");gets(str);
printf("\n\nThe string is:%s\n",st r);
proc(str);
printf("{\n\nThe string of changing is:
%s\n",str);
}
参考答案:
答案解析: