基于链表的学生信息管理系统和基于MySQL的学生信息管理系统 -C语言

来源:互联网 发布:stm8单片机自学笔记 编辑:程序博客网 时间:2024/04/27 17:28

学习C语言有两个周了,基本语法都了解了,还有一些比较生疏,然后重新温习了一下数据结构,没有涉及到的是队列,图,树,排序中的归并排序和堆排序桶排序。


用了大概一天时间码了一个学生信息管理系统,比较粗糙,可能会有不少BUG,但这算是对我这段时间的一个总结把,


结束了windows下C编程,准备进入无GUI的命令行界面的Linux下的C编程,加油!


上代码

头文件定义

#ifndef ANDREW_LIU#define ANDREW_LIU#include<conio.h> #include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <Windows.h>#define USR_PWD_LEN 20#define USR_NAME_LEN 20#define ROLE 5typedef struct usr_account_tag{char usr_name[USR_NAME_LEN];char usr_pwd[USR_PWD_LEN];char usr_role[ROLE];struct usr_account_tag *next ;}USR_ACCOUNT, *pUSR_ACCOUNT;typedef struct usr_infor_tag{int usr_id ;char usr_name[USR_NAME_LEN] ;int usr_course_id ;double usr_course_score;struct usr_infor_tag *next;}USR_INFOR,*pUSR_INFOR;pUSR_INFOR student;pUSR_ACCOUNT account;pUSR_ACCOUNT Account_build(); //建立账户链表  通过void Role_confirm(pUSR_ACCOUNT account,char usrname[]);//账户名在链表中查找   通过void show_normal_menu();//调用A权限界面    通过void show_system_menu();//调用S权限界面   通过void show_normal_search();//调用普通用户查询界面  通过void show_system_search();//调用系统用户查询界面   通过void GetPasswd(char *passwd);//密码验证void Getname(char *usrname);//账户限制void Register(pUSR_ACCOUNT *account);//注册账号   通过pUSR_ACCOUNT Search_usr_account(pUSR_ACCOUNT *account, char search_name[]);//查询帐号信息   通过void Update_usr_account(pUSR_ACCOUNT *account);//修改账户信息   通过void Delete_usr_account(pUSR_ACCOUNT *account,char name[]); //删除账户信息  通过pUSR_INFOR Student_build();//建立学生链表pUSR_INFOR Search_id(pUSR_INFOR *student, int search_id);  //学号查询    通过void Search_name(pUSR_INFOR student, char search_name[]);    //姓名查询    通过void add_usr_infor(pUSR_INFOR *student);// 添加学生信息  通过void update_usr_infor(pUSR_INFOR *student); //修改学生信息void delete_usr_infor(pUSR_INFOR *student,int id); //删除学生信息    void Input_all_student(pUSR_INFOR *student);  //输出所有学生的信息   通过pUSR_INFOR Sortlinklist(pUSR_INFOR student); //学生成绩排序    通过#endif

登录界面设计

#include "nevergiveup.h"//打开系统后建立账户表pUSR_ACCOUNT Account_build(){pUSR_ACCOUNT account;FILE *fp;char str[USR_NAME_LEN];pUSR_ACCOUNT p;account=(pUSR_ACCOUNT)calloc(1,sizeof(USR_ACCOUNT));account=NULL;    fp=fopen("D:\\Coding\\SIMS\\SIMS\\usr_account.txt","rb");if(fp==NULL)   //如果打开失败 {printf("Account open  wrong!!\n");system("pause");exit(0);}while (fscanf(fp,"%s",str)!=EOF){//printf("%s",str);p=(pUSR_ACCOUNT)calloc(1,sizeof(USR_ACCOUNT));strcpy(p->usr_name,str);fscanf(fp,"%s",str);//printf("%s",str);strcpy(p->usr_pwd,str);fscanf(fp,"%s",str);//printf("%s",str);strcpy(p->usr_role,str);p->next=account;account=p;}fclose(fp);return account;}//链表,和输入的字符串账号进行查找,如果S系统权限 返回1 用户权限void Role_confirm(pUSR_ACCOUNT account,char usrname[])   {int i=0;int j=3;char role1[ROLE]="S";char role2[ROLE]="A";char psd[USR_PWD_LEN];pUSR_ACCOUNT p;p=account;       //指向第一个账户结点while(p!=NULL){if(!strcmp(p->usr_name,usrname)){system("cls");    printf("enter usr_password: "); // while(psd[i]=getch())// {// if(i==20)   //回车停止输入// break;// if(psd[i]==13)// break;// if(psd[i]!='\b')// {// printf("*");// i++;// }// else// {// printf("\b \b ");// i--;// }// }// psd[i]='\0'; while(j>0) { GetPasswd(psd); if(!strcmp(p->usr_pwd,psd)) { system("cls"); if(!strcmp(p->usr_role,role1)) { show_system_menu(); } else if(!strcmp(p->usr_role,role2)) { show_normal_menu(); } else { printf("No privilege!!\n"); } } else { system("cls"); printf("the password is wrong! Please input again!\n"); printf("enter usr_password: ");  } j--; }      } if(j==0) { exit(-1); }else{p=p->next;}}if(p==NULL){printf("No Account!Please Register\n");printf("Inverting to the Page of Register,loading............ ");Sleep(3000);Register(&account);//注册的信息,调用函数}}void GetPasswd(char *passwd){unsigned char c;int i = 0;while ((c=getch())!='\r'){if (i<USR_PWD_LEN && !isspace(c) && isprint(c)){passwd[i++] = c;putchar('*');}else if (i>0 && c=='\b'){--i;putchar('\b');putchar(' ');putchar('\b');}else if( c=='\n' || c==' '){continue;}}if( passwd[0]=='\0')GetPasswd(passwd);else{putchar('\n');passwd[i] = '\0';}}


主界面的设计

#include "nevergiveup.h"//如果权限为A,调用void show_normal_menu(){int i,circle;system("cls");printf("******************************************************************************\n");printf("********************Student Information Management System************************\n");printf("******************************************************************************\n");printf("\n");printf("\n");printf("                       1.search student information\n");printf("                       9.            exit\n");printf("\n");printf("\n");printf("\n");printf("\n");while(fflush(stdin),printf("select the number :"),scanf("%d",&i)!=EOF){switch(i){case 1:system("cls");show_normal_search();break;case 9:exit(0);break;default:// while(scanf("%d",&circle)==EOF)// {// system("cls");// show_normal_menu();// }printf("No Privilege!!!\n");break;}}}//如果权限S调用   void show_system_menu(){int circle;int i;int id;char name[USR_NAME_LEN];char search_name[USR_NAME_LEN];pUSR_ACCOUNT p;system("cls");printf("******************************************************************************\n");printf("********************Student Information Management System************************\n");printf("******************************************************************************\n");printf("\n");printf("\n");printf("                   1.search student information \n");printf("                   2.add student information\n");printf("                   3.update student information\n");printf("                   4.delete student information\n");printf("                   5.add user account\n");printf("                   6.update user account\n");printf("                   7.delete user account\n");printf("                   8.search user account\n");printf("                   9.        exit");printf("\n");printf("\n");printf("\n");printf("\n");while(fflush(stdin),printf("select the number :"),scanf("%d",&i)!=EOF){switch(i){case 1:system("cls");show_system_search();break;case 2:add_usr_infor(&student);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 3:update_usr_infor(&student);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 4:printf("Please Input information about usr_id : \n"); //and usr_namescanf("%d %s",&id/*,name*/);delete_usr_infor(&student,id/*,name*/);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 5:Register(&account);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 6:Update_usr_account(&account);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 7:printf("Please the Account name Which you want to delete : ");scanf("%s",name);Delete_usr_account(&account,name);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 8:printf("\rPlease input the search_account_name  :");scanf("%s",search_name);p=Search_usr_account(&account,search_name);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 9:exit(0);break;default:printf("Error number! please input the number again!\n");break;}}}void show_normal_search(){int circle;pUSR_INFOR p;int i;int search_id;char search_name[USR_NAME_LEN];system("cls");    printf("******************************************************************************\n");    printf("********************Student Information Management System************************\n");    printf("******************************************************************************\n");    printf("\n");    printf("\n");    printf("                   1.search student information by name\n");    printf("                   2.search student information by id   \n");printf("                   3.           return  \n");printf("                   4.           exit  \n");    printf("\n");    printf("\n");    printf("\n");    printf("\n");while(fflush(stdin),printf("select the number :"),scanf("%d",&i)!=EOF){switch(i){case 1:printf("\rPlease input the search_name  :");scanf("%s",search_name);Search_name(student,search_name); break;case 2:printf("\rPlease input the search_id  :");scanf("%d",&search_id);//****************************p=Search_id(&student,search_id);break;case 3:system("cls");show_normal_menu();break;case 4:exit(0);break;default:printf("Please input the number again!!!");break;}}}void show_system_search(){pUSR_INFOR p;int i,circle;char search_name[USR_NAME_LEN];int search_id;system("cls");printf("******************************************************************************\n");printf("********************Student Information Management System************************\n");printf("******************************************************************************\n");printf("\n");printf("\n");printf("                   1.search all students information \n");printf("                   2.search student information by name   \n");printf("                   3.search student information by id \n");printf("                   4.            return \n");printf("                   9.            exit \n");printf("\n");printf("\n");printf("\n");printf("\n");while(fflush(stdin),printf("select the number :"),scanf("%d",&i)!=EOF){switch(i){case 1:Input_all_student(&student);while(scanf("%d",&circle)==EOF){system("cls");show_system_search();}break;case 2:printf("\rPlease input the search_name  :");scanf("%s",search_name);Search_name(student,search_name); while(scanf("%d",&circle)==EOF){system("cls");show_system_search();}break;case 3:printf("\r");printf("Please input the search_id  :");scanf("%d",&search_id);//****************************p=Search_id(&student,search_id);while(scanf("%d",&circle)==EOF){system("cls");show_system_search();}break;case 4:system("cls");show_system_menu();break;case 9:exit(0);break;default:printf("Error number! please input the number again!\n");break;}}}


账户信息查询增加更改的设计

#include "nevergiveup.h"//根据当前账号输入的账号名查询相应的账号信息。pUSR_ACCOUNT Search_usr_account(pUSR_ACCOUNT *account, char search_name[]){pUSR_ACCOUNT p;p=*account;while(p!=NULL){if(!strcmp(p->usr_name,search_name)){printf("************************Search Account Right!!!!!****************************\n");printf("                   usr_name: %s\n",p->usr_name);printf("                   usr_psd: %s\n",p->usr_pwd);printf("                   usr_role: %s\n",p->usr_role);return p;printf("loading..................................");Sleep(3000);break;}else{p=p->next;}}if(p==NULL){printf("The Account is not Rigister!!!,Please add the  Account!\n");return NULL;}}//注册新账户void Register(pUSR_ACCOUNT *account){int circle;int i=0,j=1000;char name[USR_NAME_LEN];char psd[USR_PWD_LEN];char role[ROLE];FILE *fp;pUSR_ACCOUNT p,q;p=(pUSR_ACCOUNT)calloc(1,sizeof(USR_ACCOUNT));system("cls");printf("********************Register information for new client************************\n");printf("\n");printf("\n");printf("\n");printf("\n");q=*account;while(printf("Please input name uniquely which less than twenty:"),j>0){Getname(name);while(q!=NULL){if(!strcmp(q->usr_name,name)){system("cls");printf("The usr_name has EXITed,input again\n");break;}else{q=q->next;}}if(q==NULL){printf("The  Account can use for you !\n");break;}}printf("\n");printf("\n");fp=fopen("D:\\Coding\\SIMS\\SIMS\\usr_account.txt","a");if(fp==NULL)   //如果打开失败 {printf("Service File Open Wrong!!\n");system("pause");exit(0);}fprintf(fp," %s ",name);printf("Please enter password which less than twenty: "); GetPasswd(psd);//psd[i]='\0';printf("\n");printf("\n");fprintf(fp," %s ",psd);fprintf(fp," %s ","A");strcpy(role,"A");strcpy(p->usr_name,name);strcpy(p->usr_pwd,psd);strcpy(p->usr_role,role);p->next=*account;*account=p;printf("********************Register successful!!!************************\n");fclose(fp);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}}//修改账号信息void Update_usr_account(pUSR_ACCOUNT *account){char name[USR_NAME_LEN];char psd[USR_PWD_LEN];char role[ROLE];pUSR_ACCOUNT updata,p;  //updata 修改指针  p 链表操作移动指针FILE *fp;fp=fopen("D:\\Coding\\SIMS\\SIMS\\usr_account.txt","wb");p=*account;if(fp==NULL){printf("Account Open Error!!!\n");system("pause");exit(-1);}printf("Please input the search_name which is to be uadated :\n");scanf("%s",name);updata=Search_usr_account(account,name);if(updata==NULL){printf("The Account is not EXIT!\n");}printf("loading...........................");Sleep(5000);system("cls");printf("*************************Updata the information!!!!!****************************\n");while(printf("updata the usr_name :"),scanf("%s",name)!=EOF){strcpy(updata->usr_name,name);break;}while(printf("updata the usr_psd : "),scanf("%s",psd)!=EOF){strcpy(updata->usr_pwd,psd);break;}while(printf("updata the usr_role for A or S : "),scanf("%s",role)){if((strcmp(role,"S")!=0) &&(strcmp(role,"A")!=0)){printf("the role input Error!!Input again !\n");continue;}else{strcpy(updata->usr_role,role);break;}}printf("After Revise the information:\n");printf("usr_name = %s ,usr_psd = %s ,usr_role = %s \n",updata->usr_name,updata->usr_pwd,updata->usr_role);while (p!=NULL){fprintf(fp," %s %s %s  ",p->usr_name,p->usr_pwd,p->usr_role);p=p->next;}printf("loading............");Sleep(5000);fclose(fp);}//删除账号信息void Delete_usr_account(pUSR_ACCOUNT *account,char name[]){char newname[USR_NAME_LEN];char psd[USR_PWD_LEN];char role[ROLE];pUSR_ACCOUNT ppre,pcur,ptmp,p;FILE *fp;ppre=NULL;pcur=*account;fp=fopen("D:\\Coding\\SIMS\\SIMS\\usr_account.txt","wb");if(fp==NULL){printf("The Account File Open Error!!\n");system("pause");exit(-1);}while(pcur){if(strcmp(pcur->usr_name,name)!=0){ppre=pcur;pcur=pcur->next;}else{if(ppre==NULL){ptmp=*account;*account=(*account)->next;pcur=pcur->next;free(ptmp);ptmp=NULL;printf("------------------------------Delete successful!----------------------------------");Sleep(3000);break;}else{ptmp=pcur;ppre->next=pcur->next;pcur=pcur->next;free(ptmp);printf("------------------------------Delete successful!----------------------------------");Sleep(3000);break;}}}if(pcur==NULL){printf("No the Account!!\n");}printf("\n");printf("\n");printf("\n");Sleep(5000);system("cls");p=*account;printf("******************* After Delete information the Account ********************");while(p!=NULL){printf("                       %s %s %s \n",p->usr_name,p->usr_pwd,p->usr_role);strcpy(newname,p->usr_name);fprintf(fp," %s ",newname);strcpy(psd,p->usr_pwd);fprintf(fp," %s ",psd);strcpy(role,p->usr_role);fprintf(fp," %s ",role);p=p->next;}fclose(fp);}void Getname(char *usrname){unsigned char c;int i = 0;while (  (c=getch())!='\r'){if (i<USR_NAME_LEN && !isspace(c) && isprint(c)){usrname[i++] = c;putchar(c);}else if (i>0 && c=='\b'){--i;putchar('\b');putchar(' ');putchar('\b');}else if( c=='\n' || c==' '){continue;}}if( usrname[0]=='\0'){Getname(usrname);}else{putchar('\n');usrname[i] = '\0';}}


学生信息的增加删除修改设计

#include "nevergiveup.h"pUSR_INFOR Student_build(){pUSR_INFOR student;FILE *fp;pUSR_INFOR p;int temp=0;char name[USR_NAME_LEN];double score=0.0;student=(pUSR_INFOR)calloc(1,sizeof(USR_INFOR));student=NULL;fp=fopen("D:\\Coding\\SIMS\\SIMS\\usr_infor.txt","rb");if(fp==NULL){printf("Student Information File Open wrong!! \n");system("pause");exit(0);}while(fscanf(fp,"%d",&temp/*name*/)!=EOF){//printf("%d",temp);p=(pUSR_INFOR)calloc(1,sizeof(USR_INFOR));p->usr_id=temp;fscanf(fp,"%s",name);//printf("%s",name);strcpy(p->usr_name,name);fscanf(fp,"%d",&temp);//printf("%d",temp);p->usr_course_id=temp;fscanf(fp,"%lf",&score);//printf("%f",score);p->usr_course_score=score;p->next=student;student=p;}fclose(fp);return student;}//根据当前用户所输的学号查询相应的学生信息。pUSR_INFOR Search_id(pUSR_INFOR *student, int search_id){pUSR_INFOR p;p=*student;while(p!=NULL){//查询出错if(p->usr_id==search_id){printf("***************************Search Right!!!!!****************************\n");printf("                   usr_id: %d\n",p->usr_id);printf("                   usr_name: %s\n",p->usr_name);printf("                   usr_course_id: %d\n",p->usr_course_id);printf("                   usr_course_score: %lf\n",p->usr_course_score);return p;break;}else{p=p->next;}}if(p==NULL){printf("The student's id is not exit!!!\n");return NULL;}}//根据姓名查找void Search_name(pUSR_INFOR student, char search_name[]){pUSR_INFOR p;p=student;while(p!=NULL){if(strcmp(p->usr_name,search_name)==0){printf("***************************Search Right!!!!!****************************\n");printf("                   usr_id: %d\n",p->usr_id);printf("                   usr_name: %s\n",p->usr_name);printf("                   usr_course_id: %d\n",p->usr_course_id);printf("                   usr_course_score: %lf\n",p->usr_course_score);break;}else{p=p->next;}}if(p==NULL){printf("The student's name is not exit!!!\n");}}//添加学生信息,返回指向插入的学生的指针void add_usr_infor(pUSR_INFOR *student){int temp1,temp2;double temp3;char name[USR_NAME_LEN];FILE *fp;pUSR_INFOR p,q;q=*student;   //q为查询指针p=(pUSR_INFOR)calloc(1,sizeof(USR_INFOR));while(printf("Please input the student information : \n"),printf("student_id  student_name student_course_id  student_course_score\n"),scanf("%d%s%d%lf",&temp1,name,&temp2,&temp3)!=EOF )//printf("student_id  student_name student_course_id  student_course_score\n");//scanf("%d%s%d%lf",&temp1,name,&temp2,&temp3);{if(temp1>10000||temp1<0){system("cls");printf("The usr_id is wrong !Please input again!\n");continue;}while(q!=NULL){if(q->usr_id==temp1){system("cls");printf("The  Student has Exited!!!\n");break;}else{q=q->next;}}if(q==NULL){printf("Add the Information successful!\n");break;}}//printf("Please Cheak information %d %s %d %lf\n",temp1,name,temp2,temp3);fp=fopen("D:\\Coding\\SIMS\\SIMS\\usr_infor.txt","a");if(fp==NULL){printf("Student Information File Open Wrong !\n");system("pause");exit(-1);}fprintf(fp," %d ",temp1);p->usr_id=temp1;fprintf(fp,"%s ",name);strcpy(p->usr_name,name);fprintf(fp,"%d ",temp2);p->usr_course_id=temp2;fprintf(fp,"%lf ",temp3);p->usr_course_score=temp3;p->next=*student;*student=p;printf("Add successful!!!!!!      loading.......................\n");Sleep(3000);fclose(fp);}//修改学生的信息  void update_usr_infor(pUSR_INFOR *student){int temp1,temp2;double temp3;char name[USR_NAME_LEN];pUSR_INFOR updata;pUSR_INFOR p;int search_id=0;int id,course;double score;FILE *fp;//p=(pUSR_INFOR)calloc(1,sizeof(USR_INFOR));p=*student;fp=fopen("D:\\Coding\\SIMS\\SIMS\\usr_infor.txt","wb");if(fp==NULL){printf("Student Information File Open Wrong !\n");system("pause");exit(-1);}printf("Please input the search_id which is to updata:");scanf("%d",&search_id);updata=Search_id(student,search_id);if(updata==NULL){printf("The Student is not EXIT!!\n");}//printf("usr_id = %d ,usr_name = %s ,usr_course_id = %d ,usr_course_score = %lf\n",updata->usr_id,updata->usr_name,updata->usr_course_id,updata->usr_course_score);printf("                   loading........");Sleep(10000);system("cls");printf("*************************Updata the information!!!!!****************************\n");while(printf("Updata the usr_id :"),scanf("%d",&id)!=EOF){updata->usr_id=id;break;}while(printf("Updata the usr_name : "),scanf("%s",name)!=EOF){strcpy(updata->usr_name,name);break;}while(printf("Updata the usr_course_id : "),scanf("%d",&course)!=EOF){updata->usr_course_id=course;break;}while (printf("Updata the usr_course_score : "),scanf("%lf",&score)!=EOF){updata->usr_course_score=score;break;}printf("After Revise the information:\n");printf("usr_id = %d ,usr_name = %s ,usr_course_id = %d ,usr_course_score = %lf\n",updata->usr_id,updata->usr_name,updata->usr_course_id,updata->usr_course_score);//写不会去while(p!=NULL){temp1=p->usr_id;fprintf(fp," %d ",temp1);strcpy(name,p->usr_name);fprintf(fp,"%s ",name);temp2=p->usr_course_id;fprintf(fp,"%d ",temp2);temp3=p->usr_course_score;fprintf(fp,"%lf ",temp3);//fprintf(fp," %d %s %d %d ",p->usr_id,p->usr_name,p->usr_course_id,p->usr_course_score);p=p->next;}printf("loading............");Sleep(5000);fclose(fp);}//删除学生的信息, 是返回所删除的学生的下一个学生的指针void delete_usr_infor(pUSR_INFOR *student,int id){int temp1,temp2;double temp3;char newname[USR_NAME_LEN];FILE *fp;pUSR_INFOR ppre,pcur,ptmp,p;ppre=NULL;pcur=*student;fp=fopen("D:\\Coding\\SIMS\\SIMS\\usr_infor.txt","wb");if(fp==NULL){printf("Student information File Open Error!!!\n");system("pause");exit(-1);}while(pcur){if(pcur->usr_id!=id )    //&& (strcmp(pcur->usr_name,name)!=0){ppre=pcur;pcur=pcur->next;}else{if(ppre==NULL){ptmp=*student;*student=(*student)->next;pcur=pcur->next;free(ptmp);ptmp=NULL;}else{ptmp=pcur;ppre->next=pcur->next;pcur=pcur->next;free(ptmp);}}}p=*student;while(p!=NULL){printf(" %d %s %d %d ",p->usr_id,p->usr_name,p->usr_course_id,p->usr_course_score);temp1=p->usr_id;fprintf(fp," %d ",temp1);strcpy(newname,p->usr_name);fprintf(fp,"%s ",newname);temp2=p->usr_course_id;fprintf(fp,"%d ",temp2);temp3=p->usr_course_score;fprintf(fp,"%lf ",temp3);p=p->next;}fclose(fp);}//输出所有学生 void Input_all_student(pUSR_INFOR *student){pUSR_INFOR p;p=Sortlinklist(*student);system("cls");printf("********************   All Student Information  **************************\n");while(p!=NULL){printf("usr_id = %d , usr_name = %s ,\n usr_course_id = %d , usr_course_score : %lf \n",p->usr_id,p->usr_name,p->usr_course_id,p->usr_course_score);printf("\n");p=p->next;}}//链表排序输出pUSR_INFOR Sortlinklist(pUSR_INFOR student){pUSR_INFOR pre,pnext,mark,markbehind;mark=student->next;student->next=NULL;while(mark){markbehind=mark->next;if(mark->usr_id<=student->usr_id){mark->next=student;student=mark;}else{pre=student;pnext=student->next;while(pnext && pnext->usr_id<mark->usr_id){pre=pnext;pnext=pnext->next;}mark->next=pre->next;pre->next=mark;}mark=markbehind;}return student;}

最后是主函数的调用

#include "nevergiveup.h"int main(int argc,char *argv[]){char usrname[USR_NAME_LEN];account=Account_build();student=Student_build();printf("Please Input the usr_name:");fflush(stdin);Getname(usrname); //自动留一个存储\0Role_confirm(account,usrname);    system("pause");return 0;}

其中调用的文件使用了绝对路径。系统总行数大概990行 不是很多。


下面是基于简单的Mysql的学生信息管理系统
 首先说一下 讲TXT文档导入到MYSQL数据库的方法

主要是看了这个文章 肯定比我讲的好多了 

点击打开链接

然后贴一下代码 是在链表学生信息管理系统基础上修改的

有一些在链表中的功能实现的功能在数据库版本中并没有来得及实现


#ifndef ANDREW_LIU#define ANDREW_LIU#include <WinSock2.h>#include "mysql.h"#include<conio.h> #include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <Windows.h>#define USR_PWD_LEN 20#define USR_NAME_LEN 20#define ROLE 5#define HOST "127.0.0.1"#define PORT 3306#define USR "root"#define PWD "123456"#define DB "test"#define TABLE1 "student"#define TABLE2 "account"typedef struct usr_account_tag{char usr_name[USR_NAME_LEN];char usr_pwd[USR_PWD_LEN];char usr_role[ROLE];struct usr_account_tag *next ;}USR_ACCOUNT, *pUSR_ACCOUNT;typedef struct usr_infor_tag{int usr_id ;char usr_name[USR_NAME_LEN] ;int usr_course_id ;double usr_course_score;struct usr_infor_tag *next;}USR_INFOR,*pUSR_INFOR;pUSR_INFOR student;pUSR_ACCOUNT account;pUSR_ACCOUNT Account_build(); //建立账户链表  通过void Role_confirm(pUSR_ACCOUNT account,char usrname[]);//账户名在链表中查找   通过void show_normal_menu();//调用A权限界面    通过void show_system_menu();//调用S权限界面   通过void show_normal_search();//调用普通用户查询界面  通过void show_system_search();//调用系统用户查询界面   通过void GetPasswd(char *passwd);//密码验证void Getname(char *usrname);//账户限制void Register(pUSR_ACCOUNT *account);//注册账号   通过pUSR_ACCOUNT Search_usr_account(pUSR_ACCOUNT *account, char search_name[]);//查询帐号信息   通过void Update_usr_account(pUSR_ACCOUNT *account);//修改账户信息   通过void Delete_usr_account(pUSR_ACCOUNT *account,char name[]); //删除账户信息  通过pUSR_INFOR Student_build();//建立学生链表pUSR_INFOR Search_id(pUSR_INFOR *student, int search_id);  //学号查询    通过void Search_name(pUSR_INFOR student, char search_name[]);    //姓名查询    通过void add_usr_infor(pUSR_INFOR *student);// 添加学生信息  通过void update_usr_infor(pUSR_INFOR *student); //修改学生信息void delete_usr_infor(pUSR_INFOR *student,int id); //删除学生信息    void Input_all_student(pUSR_INFOR *student);  //输出所有学生的信息   通过pUSR_INFOR Sortlinklist(pUSR_INFOR student); //学生成绩排序    通过void Login_system(char account_name[]);   //数据库验证账户名void Search_student_id(int search_id);//数据库学号查询void Search_student_name(char name[]);//数据库姓名查询void Search_student_all();  //数据库查询所有学生信息 降序输出void Add_student();//添加学生信息   通过                                      没查重void Delete_student(int search_id);//删除数据   通过void Update_student(int search_id);//修改数据库学生信息  通过void Add_account(); //添加账户  通过                                          未查重void Update_account(char search_name[]);//修改用户   通过void Delete_account(char search_name[]); //删除账户   通过void Search_account(char search_name[]); //查询账户  通过#endif


登录界面
#include "nevergiveup.h"//如果权限为A,调用void show_normal_menu(){int i,circle;system("cls");printf("********************************************************************************\n");printf("********************Student Information Management System***********************\n");printf("********************************************************************************\n");printf("\n");printf("\n");printf("                       1.search student information\n");printf("                       9.            exit\n");printf("\n");printf("\n");printf("\n");printf("\n");while(fflush(stdin),printf("select the number :"),scanf("%d",&i)!=EOF){switch(i){case 1:system("cls");show_normal_search();break;case 9:exit(0);break;default:// while(scanf("%d",&circle)==EOF)// {// system("cls");// show_normal_menu();// }printf("No Privilege!!!\n");break;}}}//如果权限S调用   void show_system_menu(){int circle;int i;int id,search_id;char name[USR_NAME_LEN];char search_name[USR_NAME_LEN];pUSR_ACCOUNT p;system("cls");printf("********************************************************************************\n");printf("********************Student Information Management System***********************\n");printf("********************************************************************************\n");printf("\n");printf("\n");printf("                   1.search student information \n");printf("                   2.add student information\n");printf("                   3.update student information\n");printf("                   4.delete student information\n");printf("                   5.add user account\n");printf("                   6.update user account\n");printf("                   7.delete user account\n");printf("                   8.search user account\n");printf("                   9.        exit");printf("\n");printf("\n");printf("\n");printf("\n");while(fflush(stdin),printf("select the number :"),scanf("%d",&i)!=EOF){switch(i){case 1:system("cls");show_system_search();break;case 2:Add_student();while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 3:printf("Please input the search_id which is to update:");scanf("%d",&search_id);Update_student(search_id);//update_usr_infor(&student);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 4:printf("Please Input information about usr_id : "); //and usr_namescanf("%d",&id/*,name*/);//delete_usr_infor(&student,id/*,name*/);Delete_student(id);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 5://Register(&account);Add_account();while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 6:printf("\rPlease input the search_account_name  :");scanf("%s",search_name);//Update_usr_account(&account);Update_account(search_name);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 7:printf("Please the Account name Which you want to delete : ");scanf("%s",name);//Delete_usr_account(&account,name);Delete_account(name);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 8:printf("\rPlease input the search_account_name  :");scanf("%s",search_name);//p=Search_usr_account(&account,search_name);Search_account(search_name);while(scanf("%d",&circle)==EOF){system("cls");show_system_menu();}break;case 9:exit(0);break;default:printf("Error number! please input the number again!\n");break;}}}void show_normal_search(){int circle;pUSR_INFOR p;int i;int search_id;char search_name[USR_NAME_LEN];system("cls");printf("********************************************************************************\n");printf("********************Student Information Management System***********************\n");printf("********************************************************************************\n");    printf("\n");    printf("\n");    printf("                   1.search student information by name\n");    printf("                   2.search student information by id   \n");printf("                   3.           return  \n");printf("                   4.           exit  \n");    printf("\n");    printf("\n");    printf("\n");    printf("\n");while(fflush(stdin),printf("select the number :"),scanf("%d",&i)!=EOF){switch(i){case 1:printf("\rPlease input the search_name  :");scanf("%s",search_name);//Search_name(student,search_name); Search_student_name(search_name);while(scanf("%d",&circle)==EOF){system("cls");show_normal_search();}break;case 2:printf("\rPlease input the search_id  :");scanf("%d",&search_id);//****************************//p=Search_id(&student,search_id);Search_student_id(search_id);while(scanf("%d",&circle)==EOF){system("cls");show_normal_search();}break;case 3:system("cls");show_normal_menu();break;case 4:exit(0);break;default:printf("Please input the number again!!!");break;}}}void show_system_search(){pUSR_INFOR p;int i,circle;char search_name[USR_NAME_LEN];int search_id;system("cls");printf("********************************************************************************\n");printf("********************Student Information Management System***********************\n");printf("********************************************************************************\n");printf("\n");printf("\n");printf("                   1.search all students information \n");printf("                   2.search student information by name   \n");printf("                   3.search student information by id \n");printf("                   4.            return \n");printf("                   9.            exit \n");printf("\n");printf("\n");printf("\n");printf("\n");while(fflush(stdin),printf("select the number :"),scanf("%d",&i)!=EOF){switch(i){case 1://Input_all_student(&student);Search_student_all(); while(scanf("%d",&circle)==EOF){system("cls");show_system_search();}break;case 2:printf("\rPlease input the search_name  :");scanf("%s",search_name);//Search_name(student,search_name); Search_student_name(search_name);while(scanf("%d",&circle)==EOF){system("cls");show_system_search();}break;case 3:printf("\r");printf("Please input the search_id  :");scanf("%d",&search_id);//****************************//p=Search_id(&student,search_id);Search_student_id(search_id);while(scanf("%d",&circle)==EOF){system("cls");show_system_search();}break;case 4:system("cls");show_system_menu();break;case 9:exit(0);break;default:printf("Error number! please input the number again!\n");break;}}}

数据库实现的登录验证

#include "nevergiveup.h"//登录验证void Login_system(char account_name[]){int j=3;char psd[USR_PWD_LEN];char role1[ROLE]="S";char role2[ROLE]="A";MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");//select * from student;sprintf(sql_line,"select * from %s where usr_name= '%s' ",TABLE2,account_name);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{res=mysql_store_result(con); //成功检索了数据的每个查询   保存在指针中row = mysql_fetch_row(res);//账户验证成功if(!strcmp(account_name,row[0])){system("cls");    printf("enter usr_password: ");while(j>0){GetPasswd(psd);if(!strcmp(row[1],psd)){system("cls");if(!strcmp(row[2],role1)){show_system_menu();}else if(!strcmp(row[2],role2)){show_normal_menu();}else{printf("No privilege!!\n");}}else{system("cls");printf("the password is wrong! Please input again!\n");printf("enter usr_password: "); }j--;}if(j==0){exit(-1);}}else{//验证失败Add_account();}mysql_free_result(res);}mysql_close(con);}

数据库实现的账户信息增删改查

#include "nevergiveup.h"//添加账户数据void Add_account(){char name[USR_NAME_LEN];char psd[USR_PWD_LEN];char role[ROLE];MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");while(printf("Add the usr_name : "),scanf("%s",name)!=EOF){break;}while(printf("Updata the usr_pwd : "),scanf("%s",psd)!=EOF){break;}//select * from student;sprintf(sql_line,"insert into %s values ('%s','%s','A')",TABLE2,name,psd);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{printf("*************************Add Account successful !***********************\n");mysql_store_result(con); //成功检索了数据的每个查询//printf("Insert successful!\n");//printf("Delete successful!\n");//printf("Update successful!\n");count=0;printf("                         usr_name = %s\n",name);printf("                         usr_pwd = %s\n",psd);//printf("total results : %d \n",count);//mysql_free_result(res);}mysql_close(con);//system("pause");//return 0;}//删除账户数据void Delete_account(char search_name[]){MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");//select * from student;sprintf(sql_line,"delete from %s where usr_name = '%s' ",TABLE2,search_name);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{printf("***********************Delete Account successful!*****************************\n");mysql_store_result(con); //成功检索了数据的每个查询//printf("Insert successful!\n");//printf("Delete successful!\n");//printf("Update successful!\n");count=0;printf("\n------------------------------------------------------------------------------\n");count++;//printf("total results : %d \n",count);//mysql_free_result(res);}mysql_close(con);//system("pause");//return 0;}void Search_account(char search_name[]){MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");//select * from student;sprintf(sql_line,"select * from %s where usr_name= '%s'",TABLE2,search_name);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{printf("*************************Search successful !*****************************\n");res=mysql_store_result(con); //成功检索了数据的每个查询//printf("Insert successful!\n");//printf("Delete successful!\n");//printf("Update successful!\n");count=0;while(row = mysql_fetch_row(res)){printf("|");for(index_field =0; index_field<mysql_num_fields(res);index_field++){printf("%-10s|\t",row[index_field]);}printf("\n------------------------------------------------------------------------------\n");count++;}//printf("total results : %d \n",count);mysql_free_result(res);}mysql_close(con);//system("pause");//return 0;}//修改用户信息void Update_account(char search_name[]){char psd[USR_PWD_LEN];char role[ROLE];char name[USR_NAME_LEN];MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");printf(" ----------------------The usr_name can not revise !-------------------------\n");while(printf("Updata the usr_pwd : "),scanf("%s",psd)!=EOF){sprintf(sql_line,"update %s set usr_pwd='%s' where usr_name='%s'",TABLE2,psd,search_name);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}//strcpy(updata->usr_name,name);break;}while(printf("Updata the usr_role : "),scanf("%s",role)!=EOF){sprintf(sql_line,"update %s set usr_role='%s' where usr_name='%s'",TABLE2,role,search_name);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}//updata->usr_course_id=course;break;}printf(" -------------------Revise  Successful!!!! After Account :-------------------\n");sprintf(sql_line,"select * from %s where usr_name='%s' ",TABLE2,search_name);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{res=mysql_store_result(con); //记录检索到的信息while(row = mysql_fetch_row(res)){//printf("|");for(index_field =0; index_field<mysql_num_fields(res);index_field++){printf("%-10s|\t",row[index_field]);}printf("\n------------------------------------------------------------------------------\n");//count++;}//printf("total results : %d \n",count);mysql_free_result(res);}mysql_close(con);//system("pause");//return 0;}

数据库实现的学生信息的增删改查

#include "nevergiveup.h"//通过id查询void Search_student_id(int search_id){MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");//select * from student;sprintf(sql_line,"select * from %s where usr_id= %d",TABLE1,search_id);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{printf("*************************Search successful !*****************************\n");res=mysql_store_result(con); //成功检索了数据的每个查询//printf("Insert successful!\n");//printf("Delete successful!\n");//printf("Update successful!\n");count=0; while(row = mysql_fetch_row(res)){ printf("|"); for(index_field =0; index_field<mysql_num_fields(res);index_field++) { printf("%-10s|\t",row[index_field]);  } printf("\n------------------------------------------------------------------------------\n"); count++; } //printf("total results : %d \n",count); mysql_free_result(res);}mysql_close(con);//system("pause");//return 0;}//通过名字查询void Search_student_name(char name[]){MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");//select * from student;sprintf(sql_line,"select * from %s where usr_name= '%s'",TABLE1,name);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{printf("***********************Search successful !*****************************\n");res=mysql_store_result(con); //成功检索了数据的每个查询//printf("Insert successful!\n");//printf("Delete successful!\n");//printf("Update successful!\n");count=0;while(row = mysql_fetch_row(res)){printf("|");for(index_field =0; index_field<mysql_num_fields(res);index_field++){printf("%-10s|\t",row[index_field]);}printf("\n------------------------------------------------------------------------------\n");count++;}//printf("total results : %d \n",count);mysql_free_result(res);}mysql_close(con);//system("pause");//return 0;}//显示所有void Search_student_all(){MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");//select * from student;sprintf(sql_line,"select * from %s order by usr_id desc",TABLE1);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{printf("***********************Search successful !*****************************\n");res=mysql_store_result(con); //成功检索了数据的每个查询//printf("Insert successful!\n");//printf("Delete successful!\n");//printf("Update successful!\n");count=0;while(row = mysql_fetch_row(res)){printf("|");for(index_field =0; index_field<mysql_num_fields(res);index_field++){printf("%-10s|\t",row[index_field]);}printf("\n------------------------------------------------------------------------------\n");count++;}//printf("total results : %d \n",count);mysql_free_result(res);}mysql_close(con);//system("pause");//return 0;}//增加数据void Add_student(){int temp1,temp2;double temp3;char name[USR_NAME_LEN];MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");while(printf("Please input the student information : \n"),printf("student_id  student_name student_course_id  student_course_score\n"),scanf("%d%s%d%lf",&temp1,name,&temp2,&temp3)!=EOF )//printf("student_id  student_name student_course_id  student_course_score\n");//scanf("%d%s%d%lf",&temp1,name,&temp2,&temp3);{if(temp1>10000||temp1<0){system("cls");printf("The usr_id is wrong !Please input again!\n");continue;}else{break;}}//select * from student;sprintf(sql_line,"insert into %s values (%d,'%s',%d,%lf) ",TABLE1,temp1,name,temp2,temp3);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{printf("***********************Add successful !*****************************\n");mysql_store_result(con); //成功检索了数据的每个查询//printf("Insert successful!\n");//printf("Delete successful!\n");//printf("Update successful!\n");printf("                 usr_id = %d\n",temp1);printf("                 usr_name = %s\n",name);printf("                 usr_course_id = %d\n",temp2);printf("                 usr_course_score = %lf\n",temp3);printf("\n------------------------------------------------------------------------------\n");//printf("total results : %d \n",count);}mysql_close(con);//system("pause");//return 0;}//删除数据void Delete_student(int search_id){MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");//select * from student;sprintf(sql_line,"delete from %s where usr_id=%d",TABLE1,search_id);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{printf("***********************Delete successful!*****************************\n");mysql_store_result(con); //成功检索了数据的每个查询//printf("Insert successful!\n");//printf("Delete successful!\n");//printf("Update successful!\n");count=0;printf("\n------------------------------------------------------------------------------\n");count++;//printf("total results : %d \n",count);//mysql_free_result(res);}mysql_close(con);//system("pause");//return 0;}//修改学生信息void Update_student(int search_id){int temp1,temp2;double temp3;char name[USR_NAME_LEN];MYSQL *con;MYSQL_RES *res;MYSQL_ROW row;char sql_line[1024]="";int rt,index_field,count;con = mysql_init((MYSQL *)0);if(!mysql_real_connect(con,HOST,USR,PWD,DB,PORT,NULL,0)) //mysql_real_connect()尝试与运行在主机上的MySQL数据库引擎建立连接{printf("mysql connect failed !\n");           //连接失败返回NULLsystem("pause");exit(-1);}printf("connect successful!\n");printf("*****************************The Information Now ***************************\n");sprintf(sql_line,"select * from %s where usr_id=%d ",TABLE1,search_id);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   {printf("mysql_real_query error !\n");system("pause");exit(-1);}else{res=mysql_store_result(con); //记录检索到的信息while(row = mysql_fetch_row(res)){//printf("|");for(index_field =0; index_field<mysql_num_fields(res);index_field++){printf("%-10s|\t",row[index_field]);}printf("\n************************Update Information Now *****************************\n");}}    printf(" ----------------------The usr_id can not revise !-------------------------\n");while(printf("Updata the usr_name : "),scanf("%s",name)!=EOF){sprintf(sql_line,"update %s set usr_name='%s' where usr_id = %d ",TABLE1,name,search_id);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}break;}while(printf("Updata the usr_course_id : "),scanf("%d",&temp2)!=EOF){sprintf(sql_line,"update %s set usr_course_id=%d where usr_id = %d",TABLE1,temp2,search_id);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}break;}while (printf("Updata the usr_course_score : "),scanf("%lf",&temp3)!=EOF){sprintf(sql_line,"update %s set usr_course_score=%lf where usr_id = %d ",TABLE1,temp3,search_id);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}break;}printf(" -------------------Revise  Successful!!!! After Information:-------------------\n");sprintf(sql_line,"select * from %s where usr_id=%d ",TABLE1,search_id);  //使用语句数组赋值   table2 table2是表的名字rt=mysql_real_query(con,sql_line,strlen(sql_line));  //  通过中间的的数组中的查询语句进行查询 参数 :MYSQL *mysql, const char *query, unsigned long lengthif (rt)   //{printf("mysql_real_query error !\n");system("pause");exit(-1);}else{res=mysql_store_result(con); //记录检索到的信息while(row = mysql_fetch_row(res)){//printf("|");for(index_field =0; index_field<mysql_num_fields(res);index_field++){printf("%-10s|\t",row[index_field]);}printf("\n------------------------------------------------------------------------------\n");//count++;}//printf("total results : %d \n",count);mysql_free_result(res);}mysql_close(con);//system("pause");//return 0;}

主函数

#include "nevergiveup.h"int main(int argc,char *argv[]){char usrname[USR_NAME_LEN];account=Account_build();student=Student_build();printf("Please Input the usr_name:");fflush(stdin);Getname(usrname); //自动留一个存储\0//Role_confirm(account,usrname);Login_system(usrname);system("pause");return 0;}

人生中第一个不算项目的项目  算是在编程世界上走出的第一步,加油大笑

0 0
原创粉丝点击