本文目錄一覽:
c語言設計用戶登錄系統,在登錄界面中,如果第一次密碼錯誤,第二次明明輸入密碼正確為什麼還是顯示錯誤
請把原碼全部貼出來,這個截圖太模糊。
我從模糊的圖片中,看到類似fread的字樣。那麼你的賬戶密碼信息是從一個文件中讀取出來。
那麼:
一、檢查你文件中的原始數據是否有寫錯。
二、用於存儲的變數空間是否夠存儲全部讀取的數據。
三、對一個文件多次讀寫後,文件指針不在初始位置,確認是否需要fseek設置文件指針初始位置。
四、檢查fopen是否執行成功。比如:多次fopen同一個文件,但前一次沒有用fclose關閉文件流。
多用戶登錄系統C語言程序
#include stdio.h
#include stdlib.h
#include “string.h”
#include “windows.h”
int total=0;
struct u_p
{
char user[20];
char pass[20];
} s[50];
void read()
{
total=GetPrivateProfileInt(“INFO”,”count”,0,”d:\\Info.dat”);
int i;
char t[5]={“\0”};
for(i=0;itotal;i++)
{
sprintf(t,”%d”,i+1);
GetPrivateProfileString(t,”USER”,””,s[i].user,20,”d:\\Info.dat”);
GetPrivateProfileString(t,”PASSWORD”,””,s[i].pass,20,”d:\\Info.dat”);
}
}
void input()
{
int p,i=0,count=0,f_u=0,f_p=0;
char user[20]={“\0”};
char password[20]={“\0”};
while(1)
{
f_u=0;
f_p=0;
system(“cls”);
printf(“當前共有%d個註冊用戶”,total);
printf(“\n\n請輸入用戶名:”);
memset(user,’\0′,20);
scanf(“%s”,user);
printf(“\n請輸入密碼:”);
memset(password,’\0′,20);
i=0;
while(1)
{
p=_getch();
if(p==10 || p==13)
{
break;
}
password[i++]=p;
printf(“*”);
}
for(i=0;itotal;i++)
{
if(strcmp(s[i].user,user)==0)
{
f_u=1;
if(strcmp(s[i].pass,password)==0)
{
f_p=1;
printf(“\n\n歡迎 %s”,user);
fflush(stdin);
_getche();
continue;
}
}
}
if(f_u==0)
{
printf(“\n\n不存在該用戶名! 選 1 重新輸入,選 2 註冊新用戶”);
int c=0;
fflush(stdin);
c=_getche();
if(c==’1′)
{
continue;
}
else if(c==’2′)
{
system(“cls”);
printf(“註冊新用戶”);
printf(“\n\n\n請輸入用戶名:”);
memset(user,’\0′,20);
scanf(“%s”,user);
printf(“\n請輸入密碼:”);
char temp[20]={“\0”} ;
i=0;
while(1)
{
p=_getch();
if(p==10 || p==13)
{
break;
}
temp[i++]=p;
printf(“*”);
}
printf(“\n請再次輸入密碼:”);
i=0;
memset(password,’\0′,20);
while(1)
{
p=_getch();
if(p==10 || p==13)
{
break;
}
password[i++]=p;
printf(“*”);
}
if(strcmp(temp,password)==0)
{
total++;
char t[5]={“\0”};
sprintf(t,”%d”,total);
WritePrivateProfileString(“INFO”,”count”,t,”d:\\Info.dat”);
WritePrivateProfileString(t,”USER”,user,”d:\\Info.dat”);
WritePrivateProfileString(t,”PASSWORD”,password,”d:\\Info.dat”);
printf(“\n\n註冊成功,請重新登錄”);
fflush(stdin);
_getch();
count=0;
read();
continue;
}
else
{
printf(“\n\n兩次密碼不一致,註冊失敗”);
fflush(stdin);
_getch();
count=0;
continue;
}
}
}
else if(f_p==0)
{
count++;
if(count=3)
{
printf(“\n\n連續輸入3次錯誤,程序將退出”);
fflush(stdin);
_getche();
return ;
}
printf(“\n\n密碼輸入錯誤,請重新輸入”);
fflush(stdin);
_getche();
}
}
return ;
}
int main(int argc, char *argv[])
{
read();
input();
return 0;
}
c語言登錄系統
#include stdio.h
#include string.h
#include stdlib.h//增加return的庫函數
int login()
{
char secercode[6];
int number = 3;
printf(“\n\n\n”);
printf(“\t\t**********歡迎使用管理系統**************”);
printf(“\n\n”);
scanf(“%s”,secercode);
while (number0)
{
if (strcmp(secercode,”88888888″)==0)
return EXIT_SUCCESS; //while語句裡面的結束循環用break是不對的
else
{
number–;
if(number=0)break;
printf(“\t\t\t 還有%d次機會\n”,number);
printf(“\n\t\t\t請輸入密碼: “);
scanf(“%s”,secercode);
}
}
if(number0) return 1;
else return 0;
}
mainMenu()
{
printf(“密碼正確 \n”);
}
main()
{
if (login() == 0)return 1;
do
{
mainMenu();
}while(1);
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/251955.html