When using gets() in C, the following warning will appear during compilation:

warning: this program uses gets(), which is unsafe.

gets() is unsafe because you give it a buffer, but you don't tell it how large the buffer actually is, nor do you know how large the input content will be. The input content may go beyond the end of the buffer, causing your program to crash.

The solution is to use fgets instead:

char buffer[bufsize];
fgets(buffer, bufsize, stdin);

Example:

// 使用 gets()
char buffer[4096];
gets(buffer);
 
// 使用 fgets() 替换 gets()
char buffer[4096];
fgets(buffer, (sizeof buffer / sizeof buffer[0]), stdin);