下列给定程序中,函数fun的功能是:依次取出字符串中所有的数字字符,形成新的字符串,并取代原字符串。 请改正函数fun中的错误,使它能得出正确的结果。 注意:不得增行或删行,也不得更改程序的结构! 试题程序: #include <stdlib.h> #in

admin2019-04-14  17

问题 下列给定程序中,函数fun的功能是:依次取出字符串中所有的数字字符,形成新的字符串,并取代原字符串。
请改正函数fun中的错误,使它能得出正确的结果。
注意:不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void fun(char *s)
{
int i,j;
for(i=0,j=0;s!=′\0′;i+ +)
if(s> =′0′&&s<=′9′)
/* * * * * * found * * * * * */
s[j]=s
/* * * * * * found * * * * * */
s[j]=″\0″;
}
void main()
{
char item[80];
system(″CLS″);
printf(″\nEnter a string:″);
gets(item);
printf(″\nThe string is:%s\n″,item);
fun(item);
printf(″\nThe string of changing is:%s\n″,
item);
}

选项

答案(1)s[j+ +]=s[i]; (2)s[j]=′\0′;

解析 题目要求依次取出字符串中所有的数字字符,因此将元素s存入s[j]后要使j加1,为下次存储做准备。s[j]=″\0″;是一个语法错误。
转载请注明原文地址:https://kaotiyun.com/show/e9Rp777K
0

最新回复(0)