用for语句设置密码
生活随笔
收集整理的這篇文章主要介紹了
用for语句设置密码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*string.h是一個和字符串處理相關的頭文件
,里面有很多字符串處理的函數,
如果你寫程序時要用到里面提供的函數的話,
就應該加。一般來說,只要有字符串處理,最好都加上。
*/
int main()
{
char *passwd = "123456";
char input[10];
int i = 0;
for (i = 0; i < 3; i++)
{
printf("請輸入密碼:>");
scanf("%s", input);
if (strcmp(passwd, input) == 0)
{
break;
}
else
{
printf("密碼輸入錯誤\n");
}
}
if (i == 3)
{
printf("三次密碼錯誤,退出系統\n");
exit(0);
}
else
{
printf("登錄成功\n");
}
system("pause");
return 0;
}
轉載于:https://blog.51cto.com/10808695/1706065
總結
以上是生活随笔為你收集整理的用for语句设置密码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《从零开始学Swift》学习笔记(Day
- 下一篇: linux下shell命令trap