gets函数是输入函数之一,它的作用是输入一个字符串
在登陆器中,账号,密码都是字符串,可以用gets函数
用gets函数输入字符串前,先定义一个字符串数组,语法格式是
gets(字符串数组名)
#include<stdio.h>
int main()
{
char cstring[20];
puts("请输入账号:");
gets(cstring);
puts("您输入的账号是:");
puts(cstring);
puts("请输入密码:");
gets(cstring);
puts("您输入的密码为:");
puts(cstring);
puts("您的账号登陆成功");
return 0;
}
上面代码中,先定义一个字符串数组cstring[20]
用gets函数为字符串数组赋值