登陸系統c語言,登錄界面c語言

本文目錄一覽:

如何用C語言編程實現用戶登錄

C語言的話,一般用戶信息存儲在結構體鏈表裡

你輸入用戶名回車以後,需要遍歷鏈表,使用strcmp()函數逐一對比鏈表裡是否存儲了你輸入的用戶名。不存在輸出“無此用戶”,存在繼續輸入密碼,將密碼與此結點的密碼信息對比,處理方式同用戶名;

至少三次輸入錯誤,可設一個整形變量index = 0,每錯誤一次執行index++,當if(index==3)成立時,輸出相應信息,並執行exit(1);

多用戶登錄系統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

typedef struct account{

    char name[32];

    char acc[16];

    char psw[16];

}Acc;

//    data是結構體數組,filename是文件絕對地址,n保存讀入的結構體數量 

void GetDataFromTxt(Acc* data, const char* filename, int* n)

{

    FILE *fp = fopen(filename, “r”);

    if( NULL == fp ){

        printf(“Open file failed or no this file!\n”);

        return;

    }

    

    int i = 0;

    while( !feof(fp) )

    {

        fscanf(fp, “%s %s %s”, data[i].name, data[i].acc, data[i].psw);

        i++;        

    }

    *n = i;    

}

int main()

{

    int i, n;

    Acc data[100];

    //    獲取數據 

    GetDataFromTxt(data, “E:\\secret.txt”, n);

    printf(“n = %d\n”, n);

    printf(“姓名    賬號          密碼\n”); 

    for(i = 0; i  n; ++i)

        printf(“%-4s %-16s %-10s\n”, data[i].name, data[i].acc, data[i].psw);

        

    //    登錄示例 

    putchar(‘\n’);

    char acc[16], psw[16];

    do{

        //    這裡只是粗略地寫了一個

        //    具體的賬號錯誤或者密碼錯誤自行發揮 

        printf(“請輸入賬號:”);

        scanf(“%s”, acc);

        printf(“請輸入密碼:”);

        scanf(“%s”, psw);

        for(i = 0; i  n; ++i)

        {

            if( strcmp(acc,data[i].acc)==0  strcmp(psw,data[i].psw)==0 ){

                printf(“登陸成功!\n”);

                break; 

            }

        }

        if( i == n ){

            printf(“賬號或密碼不正確!請重新輸入!\n\n”); 

        }else{

            break;

        }        

    }while(1);

    printf(“Bye bye!!!\n”);     

         

    return 0;

}

C語言編寫一個用戶登陸的程序?

代碼如下:

#includestdio.h

#pragma warning(disable:4996)

#includestring.h

int main()

{

int i = 0;

char password[10] = { 0 };

printf(“請輸入密碼:”);

while (i 3)

{

scanf(“%s”, password);

printf(“\n”);

if (strcmp(password, “972816”) == 0)

{

printf(“登錄成功\n”);

break;

}

else

{

i++;

if (i != 3)

printf(“再輸入一次”);

}

}

if (i == 3)

printf(“密碼錯誤三次退出登錄界面\n”);

system(“pause”);

return 0;

擴展資料:

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

引用方法:#include stdio.h

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

參考資料來源:百度百科—include

參考資料來源:百度百科—stdio.h

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/252153.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-13 17:34
下一篇 2024-12-13 17:34

相關推薦

  • Deepin系統分區設置教程

    本教程將會詳細介紹Deepin系統如何進行分區設置,分享多種方式讓您了解如何規劃您的硬盤。 一、分區的基本知識 在進行Deepin系統分區設置之前,我們需要了解一些基本分區概念。 …

    編程 2025-04-29
  • AES加密解密算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演着非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • 如何在樹莓派上安裝Windows 7系統?

    隨着樹莓派的普及,許多用戶想在樹莓派上安裝Windows 7操作系統。 一、準備工作 在開始之前,需要準備以下材料: 1.樹莓派4B一台; 2.一張8GB以上的SD卡; 3.下載並…

    編程 2025-04-29
  • Java任務下發回滾系統的設計與實現

    本文將介紹一個Java任務下發回滾系統的設計與實現。該系統可以用於執行複雜的任務,包括可回滾的任務,及時恢復任務失敗前的狀態。系統使用Java語言進行開發,可以支持多種類型的任務。…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • 如何使用Python將print輸出到界面?

    在Python中,print是最常用的調試技巧之一。在編寫代碼時,您可能需要在屏幕上輸出一些值、字符串或結果,以便您可以更好地理解並調試代碼。因此,在Python中將print輸出…

    編程 2025-04-29
  • 分銷系統開發搭建

    本文主要介紹如何搭建一套完整的分銷系統,從需求分析、技術選型、開發、部署等方面進行說明。 一、需求分析 在進行分銷系統的開發之前,我們首先需要對系統進行需求分析。一般來說,分銷系統…

    編程 2025-04-29

發表回復

登錄後才能評論