用c语言编写一个使用指针删除字符串中空格的程序

用指针噢

#include <iostream>

using namespace std;

int main()
{

char c[]= "this is a test character string";
char *p = c;
char *t = NULL;
while(*p != '\0')
{
if (*p == ' ')
{
//空格以后的所有字符串前移一个位置
t = p;
while(*t != '\0')
{
*t = *(t+1);
t++;
}
}
p++;
}

p = c;
while(*p != '\0')
{
cout << *p++;
}

cout << endl;
return 0;
}追问

while(*p != '\0')
{
cout << *p++;
}

cout << endl;
这里好像有点问题,cout没有说明。。。我有点看不懂

温馨提示:答案为网友推荐,仅供参考
相似回答