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.
Direction: gets: from standard input to memory puts: from memory to standard input note: 'gets' is unsafe, use 'fgets' instead
Nothing, it is a security hole. Use 'fgets' instead.
scanf is a function (available in C and C++)cin is an istream object (C++ only)Advice: when in doubt, use fgets+sscanf
There is nothing wrong with 'puts' but you should avoid the using of 'gets', and even 'fgets' has a disadvantage: if the input contains a binary zero, you will lose data.
read, fread, gets, fgets, getc, fgetc, getchar, getch
Direction: gets: from standard input to memory puts: from memory to standard input note: 'gets' is unsafe, use 'fgets' instead
just use fgets() from file stdio.h (not gets: it is security hole)
Nothing, it is a security hole. Use 'fgets' instead.
scanf is a function (available in C and C++)cin is an istream object (C++ only)Advice: when in doubt, use fgets+sscanf
Never use gets, use fgets instead. And strlenafterwards.
Examples: recv, read, fread, gets, fgets, scanf, fscanf
There is nothing wrong with 'puts' but you should avoid the using of 'gets', and even 'fgets' has a disadvantage: if the input contains a binary zero, you will lose data.
read, fread, gets, fgets, getc, fgetc, getchar, getch
read, fread, fgetc, fgets, fscanf etc... use the help/manual
Three.
A similarity between a Sahel and the savannah is it gets rainfall :)
It doesn't. The rate at which it cools is proportional to the difference between its temperature and that of the surrounding air. The cooler it gets, the lower that difference gets and the cooling will slow down.