C library functions - gets ()
C standard library - <stdio.h>
description
C library functionschar * gets (char * str) reads a line input stdin and stores it in str points to the string from the standard.When reading the line breaks, or when the end of file, it will stop, as the case may be.
statement
Here is () statement gets function.
char *gets(char *str)
parameter
- str - This is a pointer to a pointer to a character array, the array stores the C string.
return value
If successful, the function returns str. Have not read any characters if an error occurs or end of file, it returns NULL.
Examples
The following example demonstrates the gets () function is used.
#include <stdio.h> int main() { char str[50]; printf("请输入一个字符串:"); gets(str); printf("您输入的字符串是:%s", str); return(0); }
Let's compile and run the above program, which will result in the following:
请输入一个字符串:w3cschool.cc 您输入的字符串是:w3cschool.cc