#include<stdlib.h>
#include<stdio.h>
#include <graphics.h>
#include<ege/sys_edit.h>
// 定义学生结构体
typedef struct user{
char name[20];
char code[20];
char phone[12];
struct user *next;
} User,*pUser;
//学生进入页面
void homepage(pUser head)
{
cleardevice();
initgraph(640, 480);
setbkcolor(WHITE);
setcolor(BLACK);
setfont(20, 0, "宋体");
outtextxy(100, 100, "1.项目查询");
outtextxy(100, 150, "2. 成绩查询");
outtextxy(100, 200, "3. 分数查询");
outtextxy(100, 250, "4. 退出");
for(; is_run(); delay_fps(60))
{ //is_run()判断窗口是否存在,delay_fps(60) 作用是稳定帧率并刷新窗口 ,一秒钟循环60次
mouse_msg msg = {0}; //定义鼠标变量并且初始化
while(mousemsg())
{ //利用mousemsg()判断有没有鼠标消息
msg = getmouse();
} //获得鼠标消息
int x = msg.x;
int y = msg.y;
if (x > 100 && x < 200 && y > 100 && y < 120)
{
}
else if (x > 100 && x < 200 && y > 150 && y < 170)
{
}
else if (x > 100 && x < 200 && y > 200 && y < 220)
{
}
else if (x > 100 && x < 200 && y > 250 && y < 270)
{
break;
}
}
getch();
closegraph();
}
//管理员登录
void adlogin(pUser head)
{
initgraph(640, 480);
FILE *fp;
int flag=0;
User t,x;
inputbox_getline("请输入用户名","请输入用户名",t.name,10);
inputbox_getline("请输入密码","请输入密码",t.code,10);
fp=fopen("user.txt","r");
if(!fp)//文件为空
{
flag=0;
fclose(fp);
}
//文件不为空
else
{
while(!feof(fp))//文件到结尾时结束
{
flag=0;
fscanf(fp,"%s %s \n",x.name,x.code);
if(strcmp(t.name,x.name)==0||strcmp(t.code,x.code)==0){
flag=1;
fclose(fp);
homepage(head);
break;
}
}
}
if(flag=0)
{
MessageBox(NULL,("登录错误!请重新输入!\n"),("提示"),MB_OK|MB_ICONINFORMATION);
}
getch();
closegraph();
}
//学生登录
void login(pUser head)
{
initgraph(640, 480);
FILE *fp;
int flag=0;
User t,x;
inputbox_getline("请输入用户名","请输入用户名",t.name,10);
inputbox_getline("请输入密码","请输入密码",t.code,10);
fp=fopen("user.txt","r");
if(!fp)//文件为空
{
flag=0;
fclose(fp);
}
//文件不为空
else
{
while(!feof(fp))//文件到结尾时结束
{
flag=0;
fscanf(fp,"%s %s \n",x.name,x.code);
if(strcmp(t.name,x.name)==0&&strcmp(t.code,x.code)==0){
flag=1;
fclose(fp);
homepage(head);
break;
}
}
}
if(flag==0)
{
MessageBox(NULL,("登录错误!请重新输入!\n"),("提示"),MB_OK|MB_ICONINFORMATION);
}
getch();
closegraph();
}
//学生注册
void enroll(pUser head)
{
cleardevice();
initgraph(640, 480);
FILE *fp;
int flag=0;
User t,x;
inputbox_getline("请输入新用户名","请输入用户名",t.name,10);
inputbox_getline("请输入密码","请输入密码",t.code,10);
inputbox_getline("请输入手机号","请输入手机号",t.phone,12);
fp=fopen("user.txt","r");
if(!fp)//文件为空
{
fp=fopen("user.txt","a+");
fprintf(fp,"%s %s %s\n",t.name,t.code,t.phone);
fclose(fp);
}
//文件不为空
else
{
while(!feof(fp))//文件到结尾时结束
{
flag=0;
fscanf(fp,"%s %s %s\n",x.name,x.code,x.phone);
if(strcmp(t.name,x.name)==0||strcmp(t.phone,x.phone)==0){
flag=1;
MessageBox(NULL,("该用户已存在!请重新选择!\n"),("提示"),MB_OK|MB_ICONINFORMATION);
break;
}
}
}
if(flag==0)
{
fclose(fp);
fp=fopen("user.txt","a+");
fprintf(fp,"%s %s %s\n",t.name,t.code,t.phone);
fclose(fp);
homepage(head);
}
getch();
closegraph();
}
void zhuye(pUser head)
{
cleardevice();
setcaption("学校运动会管理系统");
initgraph(640, 480);
setbkcolor(WHITE);
setcolor(BLACK);
setfont(20, 0, "宋体");
outtextxy(100, 100, "1. 学生注册");
outtextxy(100, 150, "2. 学生登录");
outtextxy(100, 200, "3. 管理员登录");
outtextxy(100, 250, "4. 退出");
for(; is_run(); delay_fps(60))
{ //is_run()判断窗口是否存在,delay_fps(60) 作用是稳定帧率并刷新窗口 ,一秒钟循环60次
mouse_msg msg = {0}; //定义鼠标变量并且初始化
while(mousemsg())
{ //利用mousemsg()判断有没有鼠标消息
msg = getmouse();
} //获得鼠标消息
int x = msg.x;
int y = msg.y;
if (x > 100 && x < 200 && y > 100 && y < 120)
{
enroll(head);//学生注册
}
else if (x > 100 && x < 200 && y > 150 && y < 170)
{
login(head);//学生登录
}
else if (x > 100 && x < 200 && y > 200 && y < 220)
{
adlogin(head);//管理员登录
}
else if (x > 100 && x < 200 && y > 250 && y < 270)
{
break;
}
}
getch();
closegraph();
}
int main()
{
//链表头结点声明,这个头结点也就是链表的入口,你可以通过头结点,找到链表所有的数据
pUser pHead = (pUser)malloc(sizeof(User));
pHead->next=NULL;
//头结点不存放数据
User t;
//以读的方式打开user.txt文件
FILE *fp = fopen("user.txt","r+");
if(NULL == fp)
{
fp=fopen("user.txt","a+");
fprintf(fp,"%s %s %s\n",t.name,t.code,t.phone);
fclose(fp);
}
//获取链表入口,也就是头结点
pUser cur = pHead;
while(1)
{
//从user.text循环读入所有数据并依次存于链表
//先制造一个临时节点
pUser temp = (pUser)malloc(sizeof(User));
if(!temp)
exit(-1);
//下面fscanf是从文件读取信息,并存入节点的name变量和pass变量
//如果fscanf的返回值不是2,则说明后面没有数据了,也即是录入完毕
//检测到录入完毕后将分配的空间清除掉
if(2!=fscanf(fp,"%s%s%s",temp->name,temp->code,temp->phone))
{
free(temp);
break;
}
//让当前节点(链表的尾部)的后面加上读取到数据的节点
cur->next=temp;
//让当前的节点为链表尾部
cur = temp;
//使最后一个节点指向空,方便以后判断
cur->next = NULL;
}
zhuye(pHead);
return 0;
}
为什么这个代码运行出来没有点击就直接跳到了注册,还有能不能帮我看一下这个输入的数据有没有存到文件里,如果没有,能不能帮我改一下代码