String input

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )

gets function:

Read the entire line input until newline discarded line breaks, other characters are stored, and adds a null character at the end of these characters making a C string. And the puts () function used in pairs.
example:

#include <stdio.h>
int main (void)
{
	char words[81];
	
	gets(words);
	
	puts(words);
	
	return 0}

fgets function:

Description: limit the number of characters entered by the second argument to solve the overflow problem, the function designed for use with file input. Generally fputs () paired.
Function difference and gets:

  1. fgets () function reads the second argument specifies the maximum amount of characters.
  2. fgets () function does not drop line breaks.
  3. fgets () function of the third parameter specifies the file to be read. If the read data is entered from the keyboard, places stdin ( standard input ) as a parameter, the identifier is defined in stdio.h

Format: fgets(words, STLEN, stdin); fputs(words, stdout);
Example:

...
	fgets(words, 14, stdin);
	puts(words);
	fputs(words, stdout);
...
例如输入:100ask 
则输出应该是:
100ask

100ask

Why the intermediate line will be free: 100ask \ n-\ 0 is stored in the array and the puts () function will be added at the end of line breaks in the display character string.

gets_s () function:

Guess you like

Origin blog.csdn.net/Aer0_17/article/details/95323896