Hello,
Out of fgets() and gets() which function is safe to use and why?
Thanks
It depends where you are using :
fgets reads characters from stream into the string s. It stops when it reads either n - 1 characters or a newline character, whichever comes first.
gets collects a string of characters terminated by a new line from the
standard input stream stdin and puts it into s.
ajay.krish123
Junior Poster in Training
90 posts since Nov 2008
Reputation Points: 6
Solved Threads: 9
gets() is NEVER safe to use because it can corrupt the memory of your program and cause it to crash (or coredump in *nix). Read this explaination .
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343