请编写一个函数,用来删除字符串中的所有空格。
出现这个错误的原因就是下方的单引号忘记添加空格。
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <stdlib.h>
void fun (char *str)
{
int i=0;
char *p = str;
while(*p)
{
if(*p!=' ')
{
str[i++]=*p;
}
p++;
}
str[i]='\0';
}
main()
{
char str[81];
char Msg[]="Input a string:";
int n;
FILE *out;
printf(Msg);
gets(str);
puts(str);
fun(str);
printf("*** str: %s\n",str);
/******************************/
out=fopen("out.dat","w");
fun(Msg);
fprintf(out,"%s",Msg);
fclose(out);
/******************************/
}