原型
# include <stdio.h>
char *gets(char *str);
例子:
#include <stdio.h>
int main(void)
{
char str[20] = "\0"; //字符数组初始化\0
printf("请输入字符串:");
gets(str);
printf("%s\n", str);
return 0;
}
输入:hello world!
输出:hello world!
用法:参数类型为 char* 型,即 str 可以是一个字符指针变量名,也可以是一个字符数组名,数组名也可以当成指针使用。
现在来看看scanf()
#include <stdio.h>
int main(void)
{
char str[20] = "\0"; //