What would you like to do?

Between fgets and gets which function is safe to use and why?

already exists.

Would you like to merge this question into it?

already exists as an alternate of this question.

Would you like to make it the primary and merge this question into it?

exists and is an alternate of .

gets is an insecure function, its careless use can lead to errors. If you
want to use gets, consider using fgets instead, supplying stdin as
the file reference parameter.
The gets function waits until a line of input is available (unless one is already
available), and consumes the whole line including the ENTER/newline at the end.
The characters on the line are stored in the string parameter, except for the
ENTER/newline, which is discarded.
returns NULL on end-of-file, otherwise the parameter s.

The parameter given to gets must be an already allocated array of characters, not an
uninitialised char * pointer; gets will never allocate memory.
{ char a[100]; gets(line); // This is correct
{ char a[100]; char *s; s=a; gets(s); // This is correct
{ char *s; s=new char[100]; gets(s); // This is correct
{ char *s; gets(s); // This is WRONG

The array given to gets must be big enough to hold any line that could conceivably be
input. C++ and C are incapable of telling how long an array is. If it is not long enough
for the data that is read, other data (and perhaps program code) will be overwritten.
Thus gets is not a safe function for use in critical applications.
23 people found this useful
Thanks for the feedback!

Is Fabreeze safe to use on my dogs between shampoos?

  Absolutely not! Never use chemicals on your pets! You should be able to find wipes made for freshening in between baths at your local pet supply store or even wamart.

What exactly is the difference in function between the US Army and US Marine Corps?

There is a world of difference as far as training and how things are run. The Marines are more specialized for combat. All Marines regardless of occupation receive infantry tr

What is the difference between function and use?

what is the difference between function and use? I came across with this problem while I am doing my bilogy home work for instace what is the use of glucose ?and second one is

Function gets returns?

Yes, it does return. There are only few functions that do not return, like exit, exec, longjmp.

Is it safe getting an epidural?

Serious complications from an epidural procedure are extremely rare. The biggest risk that faces most patients is that the epidural will not work as effectively as desired. Th

Is getting a facebook worth it and safe?

As with many things in life it is as safe as you make it. If you use it responsibly it is quite safe, uesful and enjoyable, but if you are careless it can cause problems. Read

Is getting your tongue pierced safe?

As long as everything is sterile, and you relax your tongue and don't move it when they pierce it. By a good, safe, professional piercer? Yes. Otherwise - No. Some people's to