From cplusplus.com
The most recent revision of the C standard (2011) has definitively
removed this function from its specificationThe function is deprecated in C++ (as of 2011 standard, which follows
C99+TC3).
I just wanted to know what is the alternative to gets() in C11 standard?
In C11
getshas been substituted bygets_sthat has the following declaration:This function will read at most
n-1chars fromstdininto*str. This is to avoid the buffer overflow vulnerability inherent togets. The functionfgetsis also an option. From http://en.cppreference.com/w/c/io/gets:Given that
gets_sis defined in an extension to the standard, only optionally implemented, you should probably write your programs usingfgetsinstead. If you usefgetsonstdinyour program will also compile in earlier versions of C. But keep in mind the difference in the behavior: whengets_shas readn-1characters it keeps reading until a new line or end-of-file is reached, discarding the input. So, withgets_syou are always reading an entire line, even if only a part of it can be returned in the input buffer.