everytime i try to input my string using gets()
function, my compiler gives me warning like shown below. how to get rid of this. what am i doing wrong?
test.c:27:2: warning: ‘gets’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(temp);
^
Use fgets instead: fgets(temp, sizeof(temp), stdin); gets is deprecated because it's dangerous, it may cause buffer overflow.
If you want to read a string from standard input, you can use the gets function, the name of which stands for "get string". However, this function is deprecated -- that means it is obsolete and it is strongly suggested you do not use it -- because it is dangerous.
To avoid Buffer Overflow, fgets() should be used instead of gets() as fgets() makes sure that not more than MAX_LIMIT characters are read.
The gets() function provides no support to prevent buffer overflow if large input string are provided. It is defined in <cstdio> header file. Note: Avoid using the gets() function as it can be dangerous for the program. This function was deprecated in C++11 and removed from C++14.
Use fgets
instead:
fgets(temp, sizeof(temp), stdin);
gets
is deprecated because it's dangerous, it may cause buffer overflow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With