这个程序为什么不是死循环
程序代码:#include <stdio.h>
void delspace(char *p1);
int main(void)
{
char str[81];
do
{
puts("input a string:");
gets(str);
delspace(str);
puts(str);
puts("input any char except q to go on.");
gets(str);
}
while(*str != 'q');
puts("Quit.");
return 0;
}
void delspace(char *p1)
{
char *p2;
while (*p1 != '\0' )
{
if (*p1 == ' ')
{
p2 = p1;
while(*p2 != '\0')
{
*p2 = *(p2+1);
p2++;
}
p1--;//这里是多余的吧,删掉可以运行,不删的话感觉陷入了死循环。
}
p1++;
}
}程序是要输入一个字符串,若有空格就把它删掉。

