<p>本文实例为大家分享了C语言影院管理系统的具体代码,供大家参考,具体内容如下</p>
<div class="blockcode">
<pre class="brush:cpp;">
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#include"state.h"
#define change 3
int iCount;
int n;
//*****************注册*****************//
void router_registe(pAccout ahead)
{
system("cls");
char username[20];
char password[13];
char pass[13];
char q;
int i;
FILE *fp;
loop2:
printf("\n\n\n\n");
printf("\t\t\t\t账号:");
scanf("%s",username);
getchar();
printf("\t\t\t\t密码:");
i=0;
while (1)
{
q = getch();
if (q != 13)
{
printf("*");
password[i++] = q;
}
else {
password[i] = '\0';
printf("\n");
break;
}
}
printf("\t\t\t\t请确认密码:");
i=0;
while (1)
{
q = getch();
if (q != 13)
{
printf("*");
pass[i++] = q;
}
else {
pass[i] = '\0';
printf("\n");
break;
}
}
if(strcmp(pass,password)==0)
{
fp=fopen("e:\\课设\\Accout1.txt", "ab+");
fprintf(fp," %s %s",username,password); //把内存中的文件输入到硬盘中
fclose(fp);
system("cls");
printf("\n\n\n\n注册成功\n");
}
else goto loop2;
}
//*****************登录*****************//
pAccout router_acc(pAccout ahead)
{
pAccout p1,p2;
FILE *fp;
int m=0;
if((fp=fopen("e:\\课设\\Accout.txt", "rw"))==NULL)
{
printf("读取失败!");
return ahead;
}
ahead==NULL;
p1=(pAccout)malloc(sizeof(Accout));
while(fscanf(fp,"%s %s",p1->name,p1->pass)==2)
{
//printf("%s\n",p1->name); //读进去了
m=m+1;
if(m==1)
{
ahead->next=p1;
p2=p1;
p2->next = NULL;
}
else
{
p2->next=p1;
p2=p1;
p2->next=NULL;
}
p1=(pAccout)malloc(sizeof(Accout));
}
fclose(fp);
return ahead;
}
pAccout router_acc1(pAccout ahead)
{
pAccout p1,p2;
FILE *fp;
int m=0;
if((fp=fopen("e:\\课设\\Accout1.txt", "rw"))==NULL)
{
printf("读取失败!");
return ahead;
}
ahead==NULL;
p1=(pAccout)malloc(sizeof(Accout));
while(fscanf(fp,"%s %s",p1->name,p1->pass)==2)
{
//printf("%s\n",p1->name); //由于文件没有读入换行,读出的时候将先一个人的密码和
//printf("%s",p1->pass); //后一个人的名称
m=m+1;
if(m==1)
{
ahead->next=p1;
p2=p1;
p2->next = NULL;
}
else
{
p2->next=p1;
p2=p1;
p2->next=NULL;
}
p1=(pAccout)malloc(sizeof(Accout));
}
fclose(fp);
return ahead;
}
void login_printf()
{
system("cls");
printf("\n\n\n\n");
printf("\t\t\t★☆★☆★☆★☆★☆★☆★☆★☆\n");
printf("\t\t\t☆ ★\n");
printf("\t\t\t☆ 1.登录 ★\n");
printf("\t\t\t☆ 2.注册 ★\n");
printf("\t\t\t★ 0.退出 ☆\n");
printf("\t\t\t☆ ★\n");
printf("\t\t\t★☆★☆★☆★☆★☆★☆★☆★☆\n");
}
void login_printf1()
{
system("cls");
printf("\n\n\n\n");
printf("\t\t\t********************************\n");
printf("\t\t\t|| ||\n");
printf("\t\t\t|| 1.管理员登录 ||\n");
printf("\t\t\t|| 2.用户登录 ||\n");
printf("\t\t\t|| 0.退出 ||\n");
printf("\t\t\t|| ||\n");
printf("\t\t\t********************************\n");
}
void login_acc()
{
system("cls");
int bk;
int bb;
pAccout ahead,p1;
ahead=(pAccout)malloc(sizeof(Accout));
ahead->next=NULL;
while(1)
{
char a[200];
char b[200];
loop:
login_printf();
printf("请输入:");
scanf("%s",a);
bk=back(a);
switch(bk)
{
case 1:{
login_printf1();
printf("请输入:");
scanf("%s",b);
bb=back(b);
switch(bb)
{
case 1:{
router_acc(ahead);
ahead=login_panduan(ahead);//管理员登录
meun();
break;
}
case 2:{
router_acc1(ahead);
ahead=login_panduan(ahead);//用户登陆
menu1();
break;
}
case 0:
{
print2();
exit(0);
break;
}
default:printf("输入错误!");
Sleep(1000);
system("cls");
break;
}
if(bb!=0)//丢失此处则会无法跳出循环
break;
}
case 2:{
router_registe(ahead);
goto loop;
break;
}
case 0:{
// printf("BUG!!!!\n");测试bug!!!!!
print2();
exit(0);
break;
}
default:printf("输入错误!");
Sleep(1000);
system("cls");
break;
}
if(bk!=0)
break;
}
}
pAccout login_panduan(pAccout ahead)
{
char name1[20],pass1[20];
char q;
pAccout p1;
int i=0,j=0;
system("cls");
printf("\n\n\n\n");
loop1:
while(1)
{
j++;
p1=ahead->next;
printf("\t\t\t\t账号:");
scanf("%s",name1);
getchar();
printf("\t\t\t\t密码:");
i=0;
while (1)
{
j++;
q = getch();
if (q != 13)
{
printf("*");
pass1[i++] = q;
}
else {
pass1[i] = '\0';
printf("\n");
break;
}
}
//printf("%s",pass1);密码正确(加密最初出现问题)
while(p1!=NULL)
{
if(strcmp(name1,p1->name)==0)
{
if(strcmp(pass1,p1->pass)==0)
{
printf("\n\n\t\t\t\t登录成功!");
Sleep(2000);
return ahead;
}
else
{
p1=p1->next;
}
}
else
{
p1=p1->next;
}
if(p1==NULL)
{
printf("\n\n\n\n\t\t\t\t输入有误");
system("cls");
printf("\n\n\n\n\t\t\t\t请 |
|