Disable warning: the `gets’ function is dangerous in GCC through header files?

The obvious answer is to learn from what the compiler is trying to tell you – you should never, ever, use gets(), as it is totally unsafe. Use fgets() instead, which allows you to prevent possible buffer overruns.

#define BUFFER_SIZE 100
char buff[BUFFER_SIZE];
gets( buff);   // unsafe!
fgets( buff, sizeof(buff), stdin );   // safe

Leave a Comment