提示输入密码,以自己学号为密码,如果密码输入正确,则输出自己姓名的拼音,如果错误提示密码错误。输入输出提示字符全部用英文字符。
一个实现,供参考:
#include <stdio.h>
#include <string.h> //提供strcmp函数的原型
int main(void){
char password[10]="20220520"; //默认用今天的日期为学号,用作密码
char name[10]="ZhangSan"; //名字
char input[20]; //存放输入的密码
printf("Enter the password:"); //获取输入
gets(input);
//用strcmp函数进行输入字符串和密码字符串匹配,如果相同则打印姓名,如果不同打印错误提示信息
if(strcmp(input,password)==0){
puts(name);
}else{
printf("password error!\n");
}
return 0;
}