题目;删除字符串中的所有空格
#include <stdio.h>
char fun(char s[])
{int i=0;
char *p;
p=s;
while(*p!='\0')
{if(*p==' ')
strcpy(p,p+1);
else
p++;}
}
int main()
{char s[100];
gets(s);
fun(s);
puts(s);
}这个程序运行只有一个错误,怎么改才正确啊,尽量少改
题目;删除字符串中的所有空格
#include <stdio.h>
char fun(char s[])
{int i=0;
char *p;
p=s;
while(*p!='\0')
{if(*p==' ')
strcpy(p,p+1);
else
p++;}
}
int main()
{char s[100];
gets(s);
fun(s);
puts(s);
}这个程序运行只有一个错误,怎么改才正确啊,尽量少改
没问题描述不清楚,是警告还是错误?是语法错误还是逻辑错误?
可能的警告:fun函数里的i赋值了但没使用,把int i=0;删了就行。
可能的语法错误:严格的编译器会提示main函数必须返回一个值,最后加一句return 0;就行。
#include <stdio.h> #include<string.h> char fun(char s[]) {int i=0; char *p; p=s; while(*p!='\0') { if(*p==' ') strcpy(p,p+1); else p++; } return *p; } void main() {char s[100]; gets(s); fun(s); puts(s);
} 注意你的fun函数没有返回值;另外,strcpy函数是字符串的复制函数,最好加上“#include<string.h>”