#include
#include
int main()
{//找出字符串中的空格,并将其删除
char* str = "in ter e st ing";
int i = 0;
while (*(str+i) != '\0')
{
if (*(str + i) == ' ')
{
int a = i;
while (*(str + a) != '\0')
{
*(str + a) = *(str + a + 1);??在这一行 调试老是显示中断...
a++;
}
}
i++;
}
printf("%s\n", str);
return 0;
}
在C/C++不能存在像这种赋值方式吗?
越界了
试试
while (*(str + a) != '\0' && (a+1)<strlen(str))
因为你的字符串是存储在常量区的,是不可变的,所以会出错
你应该把字符串存储在栈空间上,比如用数组存储,就可以了,还有,要重新定义一个指针向后移动,不然在最后输出的时候只输出了‘\0’结果就会不正确