A
A
andreiglingeanu2014-02-26 17:05:00
C++ / C#
andreiglingeanu, 2014-02-26 17:05:00

Why is the fgets function not working as expected?

There is this code:

code
int main(void)
{
    char name[80];   printf("> ");

    fgets(name, 80, stdin);

    char *res = strstr("Some text, really some junk text.", name);

    if (res)
        printf("%s\n", res);
    return 0;
}

If fgets is used to read from stdin, nothing will be output.
But if you use scanf instead of fgets, then everything works with a bang.
Enlighten me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rafuck, 2014-02-26
@andreiglingeanu

End of line character.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question