C语言新手求助,实现删除输入字符串里的空格,求问bug到底在哪,谢谢!
#include <stdio.h>#define MAX 81
char *del_space (char *arr);
int main (void)
{
char arr[MAX];
puts ("Please input a string (input q to quit):");
gets (arr);
while (*arr != 'q')
{
puts (del_space (arr));
puts ("Please input a string (input q to quit):");
gets (arr);
}
return 0;
}
char *del_space (char *arr)
{
char str[MAX];
char *p;
p = str;
int i;
int j = 0;
for (i = 0; *(arr + i) != '\0'; i++)
{
if (*(arr + i) != ' ')
{
*(p + j) = *(arr + i);
j++;
}
}
*(p + j) = '\0';
return p;
}