This:
http://faq.cprogramming.com/cgi-bin/sma ... 1043284351I think you're confused... "fgets()" is the the safer version to "gets()".
"gets()" is a function to get input, that supposes the user will only enter so many characters. For instance;
- Code: Select all
char buf[10];
gets(buf);
"gets()" will assume that you're going to only get 9 characters (You have to include the "\0", but if you get more, it will still write to the array. This causes it to flip the fuck out and if you're lucky, cause a segmentation fault. If you aren't lucky, you'll be vulnerable for a buffer-overflow exploit, which can seriously fuck up your entire program.
"fgets()" on the other hand, requires you to pass the number of characters that you're going to accept, and will stop accepting chars after that. For instance;
- Code: Select all
char buf[10];
fgets(buf, 10);
It _will_ stop accepting char's at the NULL terminated char ("\n", or "\0"), so it is no longer vulnerable for a buffer overflow attack.
This really could have just been solved with a simple Google search... But I'm in a good mood.