fgets() includes the newline at the end [duplicate]

The function fgets might add a newline at the end of the string read. You’ll have to check that:

size_t ln = strlen(input) - 1;
if (input[ln] == '\n')
    input[ln] = '\0';

or even

strtok(input, "\n");

Leave a Comment