I am trying to remove white spaces from a large array read from a txt file. The strlen() of the array I'll be dealing with is around 15,000~22,500.
Here is my code:
#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];
}
}
}
}
This works for short arrays, but for larger arrays, I have to use whiteSpace() like twice to get rid of all the white spaces?
I think the algorithm is right, I don't know why it works for short arrays and glitches for larger (15,000~22,500) arrays unless I call the function twice or three times.
Thanks.