So basically I'm learning C and they taught us to use the gets() function, which I found that it was removed and cannot be used anymore. So I'm trying to learn to use the alternative, the gets_s() function, but I can't seem to. For example the following code gives me "Undefined reference to gets_s" when attempting to compile.:
char line[21];
gets_s( line, 20 );
printf( "The line entered was: %s\n", line );
A lot of people have said to use fgets() instead of gets() but I don't understand how that will work, since I want to read the user's input, not from a file.
gets_s
. – Cole Johnson Aug 31 '14 at 15:55gets_s
is only available in MSVC. Usefgets
. – Fred Foo Aug 31 '14 at 16:02getline
if your system has it (like in recent Posix spec). It is dynamically allocating the buffer for the line, so can accept very large lines (if system resources permit them). – Basile Starynkevitch Aug 31 '14 at 16:04