GNU compiler doesn't like gets() | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

GNU compiler doesn't like gets()

I typed in the gets() in gedit which is a basic text editor in linux. I compiled the program, and the compiler told me that gets() is unsafe and refused to execute. I read that gets() is depreciated, but the cryptic article I read [ https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used ] mentioned something data overflow problems. It recommends to use fgets(), but that function needs more arguments and the syntax of fgets() is unfamiliar to me. Would somebody please explain comments in this link to me in simpler English? Thanks.

28th Oct 2018, 11:51 PM
Alan Lilly
2 Answers
+ 6
gets() does not care if you read/write to memory beyond what is allocated to you, e.g. writing 10 characters to a character array of size 5. Please wait while I write and test a sample. EDIT: Nvm, even better, an existing code and thread on gets() and "why it works". https://www.sololearn.com/Discuss/1493835/?ref=app
29th Oct 2018, 12:44 AM
Hatsy Rei
Hatsy Rei - avatar
0
Did really throw an error because of gets()? Or was it just a warning? Because if it was just a warning, it still compiled your program, and you can stil execute it.
29th Oct 2018, 4:30 AM
Vlad Serbu
Vlad Serbu - avatar