Under Linux, use the
Gets (CMD)
Function error: warning:the ' gets ' function is dangerous and should isn't be used.
Workaround: Adopt
Fgets (Cmd,100,stdin);//100 is a size
Problem Solving!
Fgets reads characters from the stdin until the newline character or end of the file is read, but reads a maximum of size characters at a time. The read-out characters are stored in buffer cmd with a newline character. Returns a pointer to CMD.
Gets the line of information entered from the stdin into CMD, and then replaces the newline character with a string ending character, null. The user wants to ensure that the length of the buffer is greater than or equal to the maximum.
A detailed explanation of the gets:
char * gets (char * str);//Get string from stdin
Reads characters from stdin and stores them as a string into str until a newline character (' \ n ') or the End-of-file is R Eached.
The ending newline character (' \ n ') is not a included in the string.
A null character (' + ') is automatically appended after the last character copied to Str to signal the end of the C string .
Notice that gets does not behave exactly as Fgets does with stdin as Argument:first, the ending newline character are not Included with gets while with Fgets it is. And second, gets does not let you specify a limit in how many characters is to is read, so you must is careful with T He size of the array pointed by STR to avoid buffer overflows.
Description: The Red section explains well the "the ' function is dangerous and should not being used" for this warning reason.
Reference Link:http://www.cplusplus.com/reference/clibrary/cstdio/gets/
Using the C language gets () function error in Linux