首页 > 编程知识 正文

c语言登入系统,c语言编写登录程序

时间:2024-03-07 18:23:48 阅读:332436 作者:AZFR

本文目录一览:

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]={""};

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]={""};

char password[20]={""};

while(1)

{

f_u=0;

f_p=0;

system("cls");

printf("当前共有%d个注册用户",total); 

printf("nn请输入用户名:");

memset(user,'',20);

scanf("%s",user);

printf("n请输入密码:");

memset(password,'',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("nn欢迎 %s",user);

fflush(stdin);

_getche();

continue;

}

}

}

if(f_u==0)

{

printf("nn不存在该用户名! 选 1 重新输入,选 2 注册新用户");

int c=0;

fflush(stdin);

c=_getche();

if(c=='1')

{

continue;

}

else if(c=='2')

{

system("cls");

printf("注册新用户");

printf("nnn请输入用户名:");

memset(user,'',20);

scanf("%s",user);

printf("n请输入密码:");

char temp[20]={""} ;

i=0;

while(1)

{

p=_getch();

if(p==10 || p==13)

{

break;

}

temp[i++]=p;

printf("*");

}

printf("n请再次输入密码:");

i=0;

memset(password,'',20);

while(1)

{

p=_getch();

if(p==10 || p==13)

{

break;

}

password[i++]=p;

printf("*");

}

if(strcmp(temp,password)==0)

{

total++;

char t[5]={""};

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("nn注册成功,请重新登录");

fflush(stdin);

_getch();

count=0;

read();

continue; 

}

else

{

printf("nn两次密码不一致,注册失败");

fflush(stdin);

_getch();

count=0;

continue; 

}

}

}

else if(f_p==0)

{

count++; 

if(count=3)

{

printf("nn连续输入3次错误,程序将退出");

fflush(stdin);

_getche();

return ; 

}

printf("nn密码输入错误,请重新输入");

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("nnn");

 printf("tt**********欢迎使用管理系统**************");

 printf("nn");

 scanf("%s",secercode);

 while (number0)

 {

  if (strcmp(secercode,"88888888")==0)

  return EXIT_SUCCESS; //while语句里面的结束循环用break是不对的

  else

  {

   number--;

   if(number=0)break;

   printf("ttt 还有%d次机会n",number);

   printf("nttt请输入密码: ");

   scanf("%s",secercode);

  }

 }

 if(number0) return 1;

 else return 0;

}

mainMenu()

{

 printf("密码正确 n");

}

main()

{

 if (login() == 0)return 1;

 do

 {

  mainMenu();

 }while(1);

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。