When i pass the char * literal to trim() it seg faults but when I send an array pointer it works why is this not working?
int main(void){
/* If instead I have a char s[100] = "Hi ";
* it works as intended so why does it not work when i pass this.*/
char *s = "Hi ";
printf("<%s>\n", s);
trim(s);
printf("<%s>\n", s);
}
/* Trims all white-space off at end of string. */
void trim(char *s){
while (*s != '\0') ++s;
--s;
while (*s == ' ') --s;
*(++s) = '\0';
}