The two approaches that come to mind:
Code:
char message[20];
fgets(message, 20, stdin);
int stringLen = strlen(message);
while(stringLen > 0 && isspace (s[stringLen -1])){
stringLen--;
}
message[stringLen] = '\0';
and
Code:
char message[20];
fgets(message, 20, stdin);
int stringLen = strlen(message);
while(message[stringLen] == ' ' || message[stringLen] == '\t'){
stringLen--;
}
message[stringLen++] = '\0';
I know I can just use the first approach but I'm wondering why the second approach isn't working, it doesn't remove any trailing whitespace.