fgets()
takes 3 arguments. This is the prototype:
char *fgets(char *s, int size, FILE *stream);
So change
fgets(buffer);
to
fgets(buffer, sizeof buffer, stdin);
Also, note that fgets()
will read the newline character if the buffer has enough space. If this is something you don’t want, then you can strip it with:
buffer[strcspn(buffer, "\n")] = 0;
As suggested by @Sebastian, you can also use #define
the size:
#define SIZE 256
int main(void)
{
...
fgets(buffer, SIZE, stdin);
}
5
solved Simple program compile error with C, ‘Too few arguments’ for ‘fgets’