当前位置:网站首页>用户登录程序C语言实现
用户登录程序C语言实现
2022-07-22 22:59:00 【暴躁小程序猿】
用户登录程序实现
题目要求:编写代码实现,模拟用户登陆情景,并且只能登陆三次,(只允许输入三次密码,如果密码正确则提示登陆成功,如果三次均输入错误,则退出程序)。
代码如下:
int main()
{
int i=0;
char password[20]={
0};
//假设正确的密码是字符串'123456'
for(i=0;i<3;i++)
{
printf("请输入密码:>");
scanf("%s",password);
//两个字符串的比较不能使用==,应该使用strcmp函数,专门用来比较两个字符串;
//使用strcmp函数也必须调用#include<string.h>;
if(strcmp(password,"123456")==0)
{
printf("登陆成功\n");
break;
}
else
{
printf("密码错误请重新输入!");
}
if(i==3)
{
printf("三次密码均错误,退出程序\n");
}
}
return 0;
}
注意:
strlen函数,strcmp函数都是字符串函数,如果想使用都必须包含头文件#include<string.h>
总结
使用字符串函数时要注意引用头文件#include<string.h>.
边栏推荐
- RequestContextHolder
- 昇思易点通 | 经典卷积神经网络的深度学习解析
- Networkx visualizes graphs
- Xiaohongshu joins hands with HMS core to enjoy HD vision and grow grass for a better life
- I can't be angry with "voluntary salary reduction". I'm naked. I'm three times in four days. How can it end like this?
- go gin : 多文件上传
- 【arXiv2022】GroupTransNet: Group Transformer Network for RGB-D Salient Object Detection
- 网络参数管理
- 传统银行票据打印系统几个关键技术点简要分析
- 构造函数的初始化、清理及const修饰成员函数
猜你喜欢
随机推荐
js 正则删除span标签以及标签里面的内容
Get a control width
Redis 持久化操作 (RDB, AOF)
"Weilai Cup" 2022 Niuke summer multi school training camp 1
Promise (II)
Chapter 3 stack
Networkx visualizes graphs
Spark troubleshooting -precondition eof: no length prefix available
Google Earth engine app - a complete map legend app (land use classification of western United States)
buu web
What level of futures company is founder metaphase? Is the account opening safe and reliable?
园区/厂区怎么实现wifi上网短信认证
What type of die cutting machine can be used for paper?
Redis persistence operation (RDB, AOF)
黑马程序员-接口测试-四天学习接口测试-第二天-接口用例设计,测试点,功能测试,安全测试,性能测试,单接口测试,业务场景测试用例,postman简介,安装
Typescript对象扩展之对象原型__proto__与prototype
go gin : 多文件上传
PIP update a package
What should Alibaba cloud international account do if it receives an account risk notification?
Xiaohongshu joins hands with HMS core to enjoy HD vision and grow grass for a better life









