Removing trailing newline character from fgets() input
- by sfactor
i am trying to get some data from the user and send it to another function in gcc. the code is something like this.
printf("Enter your Name: ");
if(!(fgets(Name, sizeof Name, stdin) != NULL)) {
fprintf(stderr, "Error reading Name.\n");
exit(1);
}
However, i find that it has an \n character in the end. so if i enter John it ends up sending John\n. so how do i remove that \n and send a proper string.