赞
踩
那就对了,看过来看过来,这里有你想解决的问题的答案,
会告诉大家该怎么办:
#include<stdio.h> #include<conio.h> #include<stdlib.h> #include<string.h> #include<windows.h> #define LEN sizeof(struct stu_inf) int STU_SUM=0; int FLAG=0; int menuSubclassFail(); int userRegisterMenu(); struct stu_inf *Stu_Create(struct stu_inf *head); struct stu_inf *Stu_Delete(struct stu_inf *head); struct stu_inf *Stu_Correct(struct stu_inf *head); struct stu_inf *Stu_Search_Number(struct stu_inf *head,int number); struct stu_inf *Stu_Search_Name(struct stu_inf *head,char *name); struct stu_inf *Stu_Insert(struct stu_inf *head,struct stu_inf *stu); void Stu_Print(struct stu_inf *head); void Stu_Search(struct stu_inf *head); void Write_Data(struct stu_inf *head); void meauShow(); void userChoseFunction(int chose); void userLoginChose(); struct stu_inf *Read_Data(); struct stu_inf { int age,year,month; long int number; char name[10],sex[4],tel[15],email[30],address[50]; struct stu_inf *next; }; int chose; char userCheck[50]; char pwdCheck[16]; int isUserName; int isUserPwd; char userNameR[50] = { "root" }; char userPwdR[16] = { "abc" }; char userName[50]; char userPwd[16]; int userCdFlag = 0; void menuShow() { printf(" /*************************************/\n\n"); printf(" \t欢迎登录教务系统\n\n"); printf(" /*************************************/\n\n"); printf(" 请进行如下选择:(先注册再登录哦)\n\n\t 1.用户登录\n\n\t 2.用户注册\n\n\t 3.查看更多\n\n\t 4.退出系统\n\n"); printf("请选择:"); } void userLoginChose() { printf("用户登陆选择:\n1.普通用户\n2.管理员用户\n"); scanf("%d", &userCdFlag); getchar(); } int userRegisterMenu() { char succes; printf("用户注册成功\n输入‘y’返回登录页面\n\n"); scanf("%c", &succes); if (succes == 'y') return 0; } void userChoseFunction(int chose) { switch (chose) { case 1: userLoginChose(); if (userCdFlag == 1) { userCdFlag = 0; printf("请输入用户名:"); gets(userCheck); //user check isUserName = strcmp(userName, userCheck); printf("请输入密码:"); gets(pwdCheck); isUserPwd = strcmp(userPwd, pwdCheck); if ((isUserName == 0) && (isUserPwd == 0)) { ggb(); } else { if (menuSubclassFail() == 0) { break; } else { getchar(); userChoseFunction(1); } } printf("\n"); getchar(); } else { printf("请输入用户名:"); gets(userCheck); //user check isUserName = strcmp(userNameR, userCheck); printf("\n"); printf("请输入密码:"); gets(pwdCheck); printf("\n"); //pwd check isUserPwd = strcmp(userPwdR, pwdCheck); if ((isUserName == 0) && (isUserPwd == 0)) { ggb(); } else { if (menuSubclassFail() == 0) { break; } else { getchar(); userChoseFunction(1); } } printf("\n"); getchar(); } break; case 2: printf("请添加用户名:"); gets(userName); printf("请输入密码:"); gets(userPwd); if ((userName != NULL) && (userPwd != NULL)) { userRegisterMenu(); } printf("\n"); userCdFlag = 2; break; case 3: printf("欢迎使用该服务程序,如有疑问,请联系管理员\nQQ:2957455229@qq.com(贤哥的逆袭法宝)"); getchar(); break; default: break; } } int menuSubclassFail() { char fail; printf("/***********登录失败***********/\n\n"); printf("'y'重新输入输入\t'n'返回上一层目录\n"); scanf("%c", &fail); if (fail == 'n') return 0; else { return 1; } } void ggb() { system("cls"); char choice,choice2; struct stu_inf *head=NULL; head=Read_Data(); do { printf("\n\t\t------------------\n"); printf("\t\t学生信息教务系统\n"); printf("\t\t-*-*-*-*-*-*-*-*-*\n"); printf("\t\t(1)---录入学生信息\n"); printf("\t\t(2)---浏览学生信息\n"); printf("\t\t(3)---查询学生信息\n"); printf("\t\t(4)---删除学生信息\n"); printf("\t\t(5)---修改学生信息\n"); printf("\t\t(0)---退出系统\n"); printf("\t\t-*-*-*-*-*-*-*-*-*\n"); printf("\t\t请输入您的选择:"); choice=getche(); putchar('\n'); switch(choice) { case '1': head=Stu_Create(head); break; case '2': Stu_Print(head); break; case '3': Stu_Search(head); break; case '4': head=Stu_Delete(head); break; case '5': Stu_Correct(head); break; case '0': if(FLAG==1) { printf("\n是否将改动保存到“学生信息.txt”?(y/n)\n"); do { choice2=getche(); switch(choice2) { case 'y': Write_Data(head); break; case 'n': break; } }while(choice2!='n'&&choice2!='y'); } break; default: printf("\n无效的选项。\n"); break; } printf("\n按任意键继续..."); getch(); putchar('\n'); }while(choice!='0'); exit(0); } void main() { while(1) { system("color b4"); //设置窗口的颜色(前景色和背景色) system("MinC");//设置窗口的标题 system("mode con:cols=88 lines=30");//设置窗口的大小 menuShow(); scanf("%d", &chose); getchar(); userChoseFunction(chose); if (chose == 4) return 0; } } struct stu_inf *Stu_Create(struct stu_inf *head) { system("cls"); struct stu_inf *p; p=(struct stu_inf *)malloc(LEN); printf("\n请输入学号:"); scanf("%d",&p->number); printf("请输入姓名:"); scanf("%s",p->name); printf("请输入年龄:"); scanf("%d",&p->age); printf("请输入性别:"); scanf("%s",p->sex); printf("请输入出生年月(年月之间用空格隔开):"); scanf("%d%d",&p->year,&p->month); printf("请输入地址:"); scanf("%s",p->address); printf("请输入学生绩点:"); scanf("%s",p->tel); printf("请输入E-mail:"); scanf("%s",p->email); p->next=NULL; head=Stu_Insert(head,p); STU_SUM++; FLAG=1; printf("\n该学生的信息为:\n"); printf("-----------------------------------------------------------\n"); printf("学号\t姓名\t年龄\t性别\t出生年月\t\t地址\t绩点\tE-mail\n"); printf("%d\t%s\t%d\t%s\t%d %d\t%s\t\t%s\t%s\n", p->number,p->name,p->age,p->sex,p->year,p->month,p->address,p->tel,p->email); return head; } struct stu_inf *Stu_Insert(struct stu_inf *head,struct stu_inf *stu) { struct stu_inf *phead=head,*pstu=stu,*previous; if(head==NULL) head=stu; else { while(pstu->number > phead->number && phead->next != NULL) previous=phead,phead=phead->next; if(pstu->number <= phead->number) { if(phead==head) head=pstu; else previous->next=pstu; pstu->next=phead; } else phead->next=pstu; } return head; } void Stu_Search(struct stu_inf *head) { system("cls"); if(head==NULL) { printf("\n无学生信息。\n\n"); return ; } int number; char choice; char *name=(char *)calloc(15,sizeof(char)); do { printf("\n\n\t学生信息查询\n"); printf("------------------------------\n"); printf("\t按学号查询 请按1\n"); printf("\t按姓名查询 请按2\n"); printf("\t取消 请按0\n"); printf("------------------------------\n"); printf("请输入您的选择:"); choice=getche(); putchar('\n'); switch(choice) { case '0': return; case '1': printf("\n请输入学号:"); scanf("%d",&number); Stu_Search_Number(head,number); break; case '2': printf("\n请输入姓名:"); scanf("%s",name); Stu_Search_Name(head,name); break; default: printf("\n无效的选项。\n"); break; } printf("\n按任意键继续..."); getch(); putchar('\n'); }while(1); } struct stu_inf *Stu_Search_Number(struct stu_inf *head,int number) { struct stu_inf *p=head; if(head==NULL) printf("\n无学生信息。\n\n"); else { while(p->number != number && p->next != NULL) p=p->next; if(p->number==number) { printf("\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t绩点\tE-mail\n"); printf("%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n", p->number,p->name,p->age,p->sex,p->year,p->month,p->address,p->tel,p->email); } else printf("\n无该学生的记录。\n\n"); } return p; } struct stu_inf *Stu_Search_Name(struct stu_inf *head,char *name) { struct stu_inf *p=head; if(head==NULL) printf("\n无学生信息。\n\n"); else { while(strcmp(p->name,name) != 0 && p->next != NULL) p=p->next; if(strcmp(p->name,name)==0) { printf("\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t绩点\tE-mail\n"); printf("%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n", p->number,p->name,p->age,p->sex,p->year,p->month,p->address,p->tel,p->email); } else printf("\n无该学生的记录。\n\n"); } return p; } void Stu_Print(struct stu_inf *head) { struct stu_inf *p=head; if(head==NULL) printf("\n无学生信息。\n\n"); else { printf("\n学生总数:%d\n",STU_SUM); printf("\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t绩点\tE-mail\n"); while(p!=NULL) { printf("%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n", p->number,p->name,p->age,p->sex,p->year,p->month,p->address,p->tel,p->email); p=p->next; } } } struct stu_inf *Stu_Delete(struct stu_inf *head) { struct stu_inf *phead=head,*previous; int number; if(head==NULL) { printf("\n无学生信息。\n\n"); return NULL; } printf("\n请输入要删除的学生的学号:"); scanf("%d",&number); while(phead->number != number && phead->next != NULL) previous=phead,phead=phead->next; if(phead->number==number) { if(phead==head) head=phead->next; else previous->next=phead->next; printf("\n删除成功。\n\n"); STU_SUM--; FLAG=1; } else printf("\n无该学生的信息。\n\n"); return head; } struct stu_inf *Stu_Correct(struct stu_inf *head) { system("cls"); struct stu_inf *phead=head; int number; char choice; if(head==NULL) { printf("\n无学生信息。\n\n"); return NULL; } else { printf("\n请输入要修改的学生的学号:"); scanf("%d",&number); while(phead->number != number && phead->next != NULL) phead=phead->next; if(phead->number==number) { printf("\n该学生的信息:\n"); printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "); printf("\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t绩点\tE-mail\n"); printf("%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n", phead->number,phead->name,phead->age,phead->sex,phead->year,phead->month,phead->address,phead->tel,phead->email); printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \n"); do { printf("---------------------\n"); printf("修改姓名 请按1\n"); printf("修改年龄 请按2\n"); printf("修改性别 请按3\n"); printf("修改出生年月 请按4\n"); printf("修改地址 请按5\n"); printf("修改绩点 请按6\n"); printf("修改E-mail 请按7\n"); printf("取消 请按0\n"); printf("---------------------\n"); printf("请输入您的选择:"); choice=getche(); putchar('\n'); switch(choice) { case '0': return head; case '1': printf("\n请输入新姓名:"); scanf("%s",phead->name); FLAG=1; break; case '2': printf("\n请输入新年龄:"); scanf("%d",&phead->age); FLAG=1; break; case '3': printf("\n请输入新性别:"); scanf("%s",phead->sex); FLAG=1; break; case '4': printf("\n请输入新的出生年月(年月之间用空格隔开):"); scanf("%d%d",&phead->year,&phead->month); FLAG=1; break; case '5': printf("\n请输入新的地址:"); scanf("%s",phead->address); FLAG=1; break; case '6': printf("\n请输入新的绩点:"); scanf("%s",phead->tel); FLAG=1; break; case '7': printf("\n请输入新的E-mail:"); scanf("%s",phead->email); FLAG=1; break; default: printf("\n无效的选项。\n\n"); break; } printf("\n按任意键继续..."); getch(); putchar('\n'); }while(choice!='0'); } else printf("\n无该学生的信息。\n\n"); } return head; } void Write_Data(struct stu_inf *head) { system("cls"); FILE *fp; struct stu_inf *p; if((fp=fopen("学生信息.txt","w"))==NULL) { printf("\n*************\n"); printf("文件创建失败。\n\n"); printf("*************\n"); return; } fprintf(fp,"学生总数:%d\n",STU_SUM); if(STU_SUM!=0) fprintf(fp,"\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t绩点\tE-mail\n"); for(p=head;p!=NULL;p=p->next) fprintf(fp,"%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n", p->number,p->name,p->age,p->sex,p->year,p->month,p->address,p->tel,p->email); fclose(fp); } struct stu_inf *Read_Data() { system("cls"); FILE *fp; struct stu_inf *p,*phead,*head; if((fp=fopen("学生信息.txt","r"))==NULL) { return NULL; } fscanf(fp,"学生总数:%d\n",&STU_SUM); if(STU_SUM==0) return NULL; fscanf(fp,"\n学号\t姓名\t年龄\t性别\t出身年月\t地址\t绩点\tE-mail\n"); head=phead=p=(struct stu_inf *)malloc(LEN); fscanf(fp,"%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n", &p->number,p->name,&p->age,p->sex,&p->year,&p->month,p->address,p->tel,p->email); while(!feof(fp)) { p=(struct stu_inf *)malloc(LEN); fscanf(fp,"%d\t%s\t%d\t%s\t%d %d\t%s\t%s\t%s\n", &p->number,p->name,&p->age,p->sex,&p->year,&p->month,p->address,p->tel,p->email); phead->next=p; phead=phead->next; } phead->next=NULL; fclose(fp); return head; }
直接上大招
- main()
- {
- while(1)
- {
- system("color b4"); //设置窗口的颜色(前景色和背景色),可以直接改参数
- system("MinC");//设置窗口的标题
- system("mode con:cols=88 lines=30");//设置窗口的大小,可以自己改参数
- /*这里平时写什么
- 现在就写什么
- 上面是改变窗口大小颜色等
- 还有图片音乐字体等就不一一展示了,比较麻烦(这个是简单版通用公式)*/
- return 0;
- }
0 = 黑色 8 = 灰色
1 = 蓝色 9 = 淡蓝色
2 = 绿色 A = 淡绿色
3 = 浅绿色 B = 淡浅绿色
4 = 红色 C = 淡红色
5 = 紫色 D = 淡紫色
6 = 黄色 E = 淡黄色
7 = 白色 F = 亮白色
(对应第一行,注意:字母大小写都可以,还有输入两个相同的会没有变化。
那么,如果只输入一个数字或者字母呢,这个问题非常好,就是我上头那个代码,只在color后面输入一个d,那么这个的意思就是字体颜色,也就是淡浅绿色。
所以,输入单个数字或者字母只能代表字体颜色
输入两个,第一个是背景,第二个是字体颜色;(b4如下)
直接上去:
int chose; char userCheck[50]; char pwdCheck[16]; int isUserName; int isUserPwd; char userNameR[50] = { "root" }; char userPwdR[16] = { "abc" }; char userName[50]; char userPwd[16]; int userCdFlag = 0; void menuShow() { printf(" /*************************************/\n\n"); printf(" \t欢迎登录教务系统\n\n"); printf(" /*************************************/\n\n"); printf(" 请进行如下选择:(先注册再登录哦)\n\n\t 1.用户登录\n\n\t 2.用户注册\n\n\t 3.查看更多\n\n\t 4.退出系统\n\n"); printf("请选择:"); } void userLoginChose() { printf("用户登陆选择:\n1.普通用户\n2.管理员用户\n"); scanf("%d", &userCdFlag); getchar(); } int userRegisterMenu() { char succes; printf("用户注册成功\n输入‘y’返回登录页面\n\n"); scanf("%c", &succes); if (succes == 'y') return 0; } void userChoseFunction(int chose) { switch (chose) { case 1: userLoginChose(); if (userCdFlag == 1) { userCdFlag = 0; printf("请输入用户名:"); gets(userCheck); //user check isUserName = strcmp(userName, userCheck); printf("请输入密码:"); gets(pwdCheck); isUserPwd = strcmp(userPwd, pwdCheck); if ((isUserName == 0) && (isUserPwd == 0)) { ggb(); } else { if (menuSubclassFail() == 0) { break; } else { getchar(); userChoseFunction(1); } } printf("\n"); getchar(); } else { printf("请输入用户名:"); gets(userCheck); //user check isUserName = strcmp(userNameR, userCheck); printf("\n"); printf("请输入密码:"); gets(pwdCheck); printf("\n"); //pwd check isUserPwd = strcmp(userPwdR, pwdCheck); if ((isUserName == 0) && (isUserPwd == 0)) { ggb(); } else { if (menuSubclassFail() == 0) { break; } else { getchar(); userChoseFunction(1); } } printf("\n"); getchar(); } break; case 2: printf("请添加用户名:"); gets(userName); printf("请输入密码:"); gets(userPwd); if ((userName != NULL) && (userPwd != NULL)) { userRegisterMenu(); } printf("\n"); userCdFlag = 2; break; case 3: printf("欢迎使用该服务程序,如有疑问,请联系管理员\nQQ:2957455229@qq.com(贤哥的逆袭法宝)"); getchar(); break; default: break; } } int menuSubclassFail() { char fail; printf("/***********登录失败***********/\n\n"); printf("'y'重新输入输入\t'n'返回上一层目录\n"); scanf("%c", &fail); if (fail == 'n') return 0; else { return 1; } } int userCdFlag = 0;
当然了这样差不多,但是还是差一点,因为要输入才能判断
- void main()
- {
- while(1)
- {
- system("color b4"); //设置窗口的颜色(前景色和背景色)
- system("MinC");//设置窗口的标题
- system("mode con:cols=88 lines=30");//设置窗口的大小
- menuShow();
- scanf("%d", &chose);
- getchar();
- userChoseFunction(chose);
- if (chose == 4) return 0;
-
- }
- }
所以主函数还要加上一些东西才行,不过问题都不大,最上面的代码是完整的,需要改变上面大家可以进行改变函数名称就行。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。