首页 > 编程知识 正文

c语言文件管理代码,C语言网站用户管理系统

时间:2023-05-06 16:49:40 阅读:110701 作者:3374

#include<stdio.h>#include<stdlib.h>#include<string.h>FILE *fp;struct xsonde{int xh;char xm[15];int gs;int yy;int wl;double pj;struct xsonde *next;};void *bc(struct xsonde *head)//保存在文件夹中的函数{struct xsonde *p;p=head;if((fp=fopen("xxxxxxxxxxxxhsdwx.txt","w"))==NULL){printf("打不开此文件n");exit(0);}while(p!=NULL){fprintf(fp,"学号:%d姓名:%s高数成绩:%d英语成绩:%d物理成绩:%dn",p->xh,p->xm,p->gs,p->yy,p->wl);p=p->next;}printf("数据已写入文件夹nnn");fclose(fp);return 0;}void *ck(struct xsonde *head)//查看保存在文件夹中的函数{int i=0;char a;struct xsonde *p;p=head;if((fp=fopen("xxxxxxxxxxxxhsdwx","r"))==NULL){printf("打不开此文件n");exit(0);}printf("n所有人成绩为:n");a=getc(fp);while(!feof(fp)){ putchar(a);a=getc(fp);} fclose(fp);return 0;}struct xsonde *lr()//录入成绩函数{int i=0,n=0;struct xsonde *p1,*p2,*head;p1=p2=(struct xsonde *)malloc(sizeof(struct xsonde));printf("第%d名学生学号:",i+1);scanf("%d",&p1->xh);printf("姓名:");scanf("%s",p1->xm);printf("高数成绩:");scanf("%d",&p1->gs);printf("英语成绩:");scanf("%d",&p1->yy);printf("物理成绩:");scanf("%d",&p1->wl);head=NULL;while(n>=0){n++;i++;if(i==1)head=p1;else p2->next=p1;p2=p1;p1=(struct xsonde *)malloc(sizeof(struct xsonde));printf("第%d名学生学号:",i+1);scanf("%d",&p1->xh);if(p1->xh==0){printf("录入成绩完成n");break;}printf("姓名:");scanf("%s",p1->xm);printf("高数成绩:");scanf("%d",&p1->gs);printf("英语成绩:");scanf("%d",&p1->yy);printf("物理成绩:");scanf("%d",&p1->wl);}p2->next=NULL;return (head);}struct xsonde *xgxm(struct xsonde *head)//修改学号和姓名函数{int i,j,a;char b[15];struct xsonde *p;p=head;printf("请选择:n1、修改学号n2、修改姓名n");scanf("%d",&j);printf("输入需要修改学生的原学号:");scanf("%d",&i);while(p->xh!=i){p=p->next;if(p==NULL){printf("无此学号!n");return(head);}}switch(j){case(1):{printf("输入修改后的新学号:");scanf("%d",&a);p->xh=a;break;}case(2):{printf("输入修改后的姓名:");scanf("%s",b);strcpy(p->xm,b);break;}default:printf("请选择正确的选项!");}printf("修改完成n");bc(head);return (head);}struct xsonde *xgcj(struct xsonde *head)//修改成绩函数{int i,j,a;struct xsonde *p;p=head;printf("输入需要修改成绩学生的学号:");scanf("%d",&i);while(p->xh!=i){p=p->next;if(p==NULL){printf("无此学号!n");return(head);}}printf("输入需要修改成绩的科目:n1、高数n2、英语n3、物理n");scanf("%d",&j);printf("输入修改后的新成绩:");scanf("%d",&a);if(j==1) p->gs =a;if(j==2) p->yy =a;if(j==3) p->wl =a;printf("修改完成n");bc(head);return (head);}struct xsonde *scsj(struct xsonde *head)//删除数据函数{int i;struct xsonde *p,*q;p=head;printf("输入要删除学生的学号:");scanf("%d",&i);while(p->xh!=i){p=p->next;if(p==NULL){printf("无此学号!n");return(head);}}p=head;if(head->xh==i){head=head->next;bc(head);return(head);}else{p=head;q=head;while((p->xh!=i)&&(p->next!=NULL)){q=p;p=p->next;}q->next=p->next;}free(p);printf("删除成功!n");bc(head);return(head);}struct xsonde *jspj(struct xsonde *head)//查询平均成绩函数{int sum=0,i;struct xsonde *p;p=head;printf("输入查询平均成绩学生的学号:");scanf("%d",&i);while(p->xh!=i){p=p->next;if(p==NULL){printf("无此学号!n");return(head);}}sum=(p->gs+p->yy+p->wl );p->pj =sum/3.0;printf("该生平均成绩为:%4.2f",p->pj );printf("n");return (head);}struct xsonde *cxcj(struct xsonde *head)//查询成绩函数{int i,sum;struct xsonde *p;p=head;printf("输入查询成绩学生的学号:");scanf("%d",&i);while(p->xh!=i){p=p->next;if(p==NULL){printf("无此学号!n");return(head);}}sum=(p->gs+p->yy+p->wl );p->pj =sum/3.0;printf("高数:%dt英语%dt物理%dt平均成绩%4.2f",p->gs,p->yy,p->wl,p->pj );printf("n");return (head);}struct xsonde *xz(struct xsonde *head)//添加同学{struct xsonde *p,*q;p=head;q=(struct xsonde *)malloc(sizeof(struct xsonde));while(p->next!=NULL){p=p->next;}printf("输入要新增学生的学号:");scanf("%d",&q->xh);printf("姓名:");scanf("%s",q->xm);printf("高数成绩:");scanf("%d",&q->gs);printf("英语成绩:");scanf("%d",&q->yy);printf("物理成绩:");scanf("%d",&q->wl);p->next=q;q->next=NULL;printf("添加成功!n");bc(head);return(head);}int main ()//主函数{struct xsonde *head;int i=0,a;printf("下面录入各学生成绩:(学号输入 0 时停止录入)n");head=lr();bc(head);while(i==0){printf("选择下方功能:n");printf("1.修改或学号及姓名n2.修改成绩n3.删除学生数据n4.计算平均成绩n5.按学号查询成绩n6.查看所有同学成绩n7.新增同学n8.退出n");printf("选择对应序号:");scanf("%d",&a);switch(a){case(1):xgxm(head);break;case(2):xgcj(head);break;case(3):scsj(head);break;case(4):jspj(head);break;case(5):cxcj(head);break;case(6):ck(head);break;case(7):xz(head);break;case(8):i++;break;default:printf("错误!n");}if(i==0)printf("n若退出,输入 1 ,若不退出,输入 0 :");else break;scanf("%d",&i);printf("nn");}printf("n");return 0;}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。