Hi everyone,
I have been having trouble writing a seemingly easy program. My program must remove all white space from a string without the use of string functions or an auxiliary string.
Here is my attempt to solve this,
Code:
void removewhitespace(char *str)
{
int i=0,j=0;
while(str[i] != '\0'){
if(str[i] != (' '||'\n'||'\t')){ //both characters increment
str[j]=str[i];
i++;
j++;}
else{ //if character is white space, i increments and starts replacing the white space at j.
i++;
}
}
}
I get a segmentation fault on line 6. I honestly can't figure out what is causing this problem. I would think that my while statement would stop the program from accessing memory beyond the bounds of the string.