當前位置:首頁 » 編程語言 » c語言密碼登錄

c語言密碼登錄

發布時間: 2023-03-02 12:51:17

『壹』 c語言編寫用戶登錄程序

代碼如下:

#include<stdio.h>

#pragma warning(disable:4996)

#include<string.h>

int main()

{

int i = 0;

char password[10] = { 0 };

printf("請輸入密碼:");

while (i < 3)

{

scanf("%s", password);

printf(" ");

if (strcmp(password, "972816") == 0)

{

printf("登錄成功 ");

break;

}

else

{

i++;

if (i != 3)

printf("再輸入一次");

}

}

if (i == 3)

printf("密碼錯誤三次退出登錄界面 ");

system("pause");

return 0;

(1)c語言密碼登錄擴展閱讀:

#include後面有兩種方式,<>;和""前者先在標准庫中查找,查找不到在path中查找。後者為文件路徑,若直接是文件名則在項目根目錄下查找。

引用方法:#include<stdio.h>

注意事項:在TC2.0中,允許不引用此頭文件而直接調用其中的函數,但這種做法是不標準的。也不建議這樣做。以避免出現在其他IDE中無法編譯或執行的問題。

『貳』 c語言,字元串密碼登錄程序

這樣修改,是否符合原來的題意?

『叄』 c語言寫登錄界面 賬號密碼登錄錯誤三次 管理員登錄 員工登錄兩個

#include<stdio.h>
#include<stdlib.h>

#defineMAXL100
#defineMAX_ERROR_TIME3

interrorTime=0;

intgetLen(chars[]){
intl=0;
for(l=0;s[l]!='';l++);
returnl;
}

voidspaceRow(){
printf("|");
for(inti=2;i<MAXL;++i)printf("");
printf("| ");
}

voidborderRow(){
for(inti=0;i<MAXL;++i)printf("-");
printf(" ");
}

voidfill(introw){
if(row<4){
for(inti=0;i<=(5-row)>>1;++i)
spaceRow();
}
elsespaceRow();
}

voidshow(char*s[],introw){
borderRow();
fill(row);

for(inti=0;i<row;++i){
intlen=getLen(s[i]),mid=(MAXL-len)>>2;
printf("|");
for(intj=1;j<mid;++j)printf("");
printf("%s",s[i]);
for(intj=0;j<MAXL-mid-len-1;++j)printf("");
printf("| ");
}

fill(row);
borderRow();
}

intcmp(chara[],charb[]){
for(inti=0;a[i]!=''&&b[i]!='';i++)
if(a[i]!=b[i])return0;
return1;
}

voidIndex(){
char*a[3];
a[0]="1.登錄";
a[1]="2.注冊";
a[2]="3.退出";
show(a,3);
}

boollog(){
system("cls");
if(errorTime>=MAX_ERROR_TIME){
printf("錯誤次數達到3次,無法登入 ");
return0;
}
printf("請輸入賬號:");
charuser[1024],psw[1024],uc[1024],pc[1024];
scanf("%s",user);
printf("請輸入密碼:");
scanf("%s",psw);

FILE*u=fopen("UserName.txt","r");
FILE*p=fopen("PassWord.txt","r");

while(fgets(uc,1024,u)){
fgets(pc,1024,p);
if(cmp(uc,user)&&cmp(psw,pc)){fclose(u);fclose(p);return1;}
if(feof(u))break;
}
fclose(u);
fclose(p);
return0;
}

boolreg(){
system("cls");
charstr[1024];
printf("請輸入賬號(為-1則退出注冊):");
scanf("%s",str);
if(str[0]=='-'&&str[1]=='1'&&str[2]=='')returnfalse;
FILE*fp=fopen("UserName.txt","a+");
fputs(str,fp);
fputs(" ",fp);
fclose(fp);
printf("請輸入密碼:");
scanf("%s",str);
fp=fopen("PassWord.txt","a+");
fputs(str,fp);
fputs(" ",fp);
fclose(fp);
returntrue;
}

intmain(){
ints,flag=1;
Index();
while(flag&&scanf("%d",&s)){
switch(s){
case1:if(log())printf("登錄成功 ");
else{printf("登錄失敗 ");errorTime++;}
break;
case2:
if(reg())printf("注冊成功 ");
elseprintf("取消注冊 ");
break;
case3:flag=0;break;
}
printf("按任意鍵繼續 ");
getchar();
getchar();
system("cls");
Index();
}
}

熱點內容
隨機啟動腳本 發布:2025-07-05 16:10:30 瀏覽:520
微博資料庫設計 發布:2025-07-05 15:30:55 瀏覽:21
linux485 發布:2025-07-05 14:38:28 瀏覽:302
php用的軟體 發布:2025-07-05 14:06:22 瀏覽:751
沒有許可權訪問計算機 發布:2025-07-05 13:29:11 瀏覽:428
javaweb開發教程視頻教程 發布:2025-07-05 13:24:41 瀏覽:692
康師傅控流腳本破解 發布:2025-07-05 13:17:27 瀏覽:236
java的開發流程 發布:2025-07-05 12:45:11 瀏覽:681
怎麼看內存卡配置 發布:2025-07-05 12:29:19 瀏覽:280
訪問學者英文個人簡歷 發布:2025-07-05 12:29:17 瀏覽:831