找了三个小时,还是不知道在那出错
#include <windows.h> #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define m 100
HANDLE hConsole;
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(hConsole, coord);
}
struct yonghu { /*个人注册信息*/
char name[8];
char sex[4];
char class[20];
char telephone[14];
char qin_hao[3];
}student;
struct deng_lu { /*个人登录信息*/
char zhang_hao[20];
char mi_ma[6];
}yong_hu, stud;
void zhu_ce() /*注册界面*/
{
FILE *ip, *fp;
printf("请输入注册的个人信息:\n");
printf("名字\t性别\t学部班级\t电话号码\t寝号\t用户名\t密码\n");
scanf("%s%s%s%s%s%s%s", student.name, student.sex, student.class, student.telephone, student.qin_hao, yong_hu.zhang_hao, yong_hu.mi_ma);
if((ip = fopen("student2.txt","a+")) == NULL) {
printf("不能打开这个文件\n");
return;
}
if(fwrite(&student,sizeof(struct yonghu),1,ip) != 1)
printf("信息写入错误!");
fprintf(ip,"\n");
fclose(ip);
if((fp = fopen("denglu.txt","a+")) == NULL) {
printf("不能打开这个文件\n");
return;
}
if(fwrite(&yong_hu, sizeof(struct deng_lu), 1, fp) != 1)
printf("信息写入错误!");
fprintf(fp,"\n");
fclose(fp);
}
int jian_ce_1(char* xin_xi) /*登录账号检测*/
{
int b;
FILE *ip;
ip = fopen("denglu.txt", "r+");
for (b = 0; b < m; b++) {
if(b)
{
fseek(ip, b * sizeof(struct deng_lu) + 2, 0);
fread(&stud, sizeof(struct deng_lu), 1, ip);
}
else
fread(&stud, sizeof(struct deng_lu), 1, ip);
if(strcmp(stud.zhang_hao, xin_xi) == 0) {
return (1);
}
continue;
}
return (0);
}
int jian_ce_2(char* xin_xi) /*登录密码检测*/
{
int d;
FILE *ip;
ip = fopen("denglu.txt", "r+");
for (d = 0; d < m; d++) {
if(d)
{
fseek(ip, d * sizeof(struct deng_lu) + 2, 0);
fread(&stud, sizeof(struct deng_lu), 1, ip);
}
else
fread(&stud, sizeof(struct deng_lu), 1, ip);
if(strcmp(stud.mi_ma, xin_xi) == 0) {
return (1);
}
continue;
}
return (0);
}
void deng_lu() /*登录界面*/
{
int p, q, j;
char new_zhang_hao[18];
char new_mi_ma[6];
printf("\t\t\t登录界面\t\t\t\n\n");
printf("\t\t\t|---------------------------|\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 用户名: |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 密 码 : |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| |\n");
printf("\t\t\t|---------------------------|\n");
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(34, 4);
scanf("%s", new_zhang_hao);
p = jian_ce_1(new_zhang_hao);
if (!p)
printf("不存在这个账号:请先注册:\n");
else {
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(34, 6);
for (j = 0; j < 6; j++) {
new_mi_ma[j] = getch();
printf("*");
}
q = jian_ce_2(new_mi_ma);
if(!q) {
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(34, 4);
printf("密码错误:请重新输入:\n");
}
else {
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(34, 4);
printf("登录成功\n");
}
}
}
void zhu_jie_mian()
{
int num1;
printf("校园寝室管理系统\n\n\n");
printf("\t\t\t 主界面\t\t\t\n\n");
printf("\t\t\t|---------------------------|\n");
printf("\t\t\t| 1-登录 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 2-注册 |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 3-退出 |\n");
printf("\t\t\t|---------------------------|\n");
printf("请按编号选择要进入的界面:\n");
scanf("%d", &num1);
switch(num1) {
case 1 : deng_lu(); break; /*登录*/
case 2 : zhu_ce(); break; /*注册*/
case 3 : printf("欢迎下次使用!\n");
break; /*退出*/
default : printf("请重新选择!\n");
break;
}
void zhujiemian()
{
int i;
char num[6];
char mima[6];
printf("*******************************************************************************\n\n\n");
printf("\t\t\t 校园寝室管理系统\t\t\t\n\n");
printf("\t\t\t|---------------------------|\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 管理员: |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| 密 码 : |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| |\n");
printf("\t\t\t| |\n");
printf("\t\t\t|---------------------------|\n");
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(34, 7);
scanf("%s", num);
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(34, 9);
for (i = 0; i < 6; i++) {
mima[i] = getch();
printf("*");
}
if (num[0] == 'l' && num[1] == 'i' && num[2] == 'n' && num[3] == 'u' && num[4] == 's' && mima[0] == '4' &&
mima[1] == '5' && mima[2] == '2' && mima[3] == '3' && mima[4] == '2' && mima[5] == '3' ) {
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(34, 15);
printf("登录成功\n");
zhu_jie_mian();
}
else {
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(28, 15);
printf("登录失败,请重新输入!\n");
}
}
void main() /*主函数*/
{
zhujiemian();
}