我试图从一个从txt文件读取的大型数组中删除空格。 我要处理的数组的strlen()大约是15,000〜22,500。C - 删除空格
这里是我的代码:
#include <stdio.h>
#include <ctype.h>
void whiteSpace(char str[]){
int i, j;
for (i = 0; str[i] != 0; i ++){
if (isspace(str[i])){
for(j = i; str[j] != 0; j ++){
str[j] = str[j + 1];
}
}
}
}
这适用于短数组,但对于更大的阵列,我必须使用空格(),如两次摆脱所有的白色空间?我认为算法是正确的,我不知道为什么它适用于短阵列和大型(15,000〜22,500)阵列的毛刺,除非我调用函数两次或三次。
谢谢。
考虑动态内存allocation.malloc这样更大的存储的东西 – minigeek
[删除空间从C中的字符串?](http://stackoverflow.com/questions/1726302/removing-spaces-from-a-string-in- c) – BLUEPIXY