Using fgets, removing last character
Hello,
I have ran into a slight problem. Of course I always did it the bad way I guess and now I'm looking for a solution. Here is my current code:
Code:
int main() {
char sentence[256];
printf("Enter your sentence here: ");
fgets(sentence, 255, stdin);
sentence[strlen(sentence)-1] = '\0';
printf("Sentence: %s\n", sentence);
return 0;
}
The only thing is, I don't like calling strlen() in that situtation. I've tried everything from *(sentence--) = '\0' to sentence[*sentence-1] = '\0' and I just can't seem to find a way.
To keep an open mind, is there actually a way or is this [current way] the best way?
Thank you for your time,
- Stack Overflow