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,
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.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++; } } }



LinkBack URL
About LinkBacks



Why is it that the string created by a pointer doesn't work the same as a string created as an array?