c语言实现简易学生管理系统
1.内容用到结构体,链表,函数,文件操作
2.该代码实现了增删改查,不过缺点,没有进行链表的内存释放会造成内存泄漏,写还是挺简单的,不过懒得写了
直接上代码自己感悟:
代码:
#include<stdio.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<string.h>
#include<stdlib.h>
typedef struct student{
char name[64];
int age;
char id[24];
char sex[5];
float cn;
float en;
struct student *next;
}stu;
void menu(void)
{
int choice;
printf("welcome to student systems\n");
printf("1.add 2.delect \n");
printf("3.show 4.update \n");
printf("0.exit\n");
printf("\n");
}
void add(void)
{
int nu;
FILE *pf=NULL;
pf=fopen("student.txt","a");
if(NULL==pf)
{
printf("open false!\n");
return ;
}
while(1)
{
getchar();
printf("input 1=contine;0=break;\n");
scanf("%d",&nu);
if(!nu)
{
break;
}
stu*s=(stu*)malloc(sizeof(stu));
s->next=NULL;
getchar();
printf("please input student name:");
fgets(s->name,64,stdin);
s->name[strlen(s->name)-1]='\0';
printf("please input age:");
scanf("%d",&(s->age));
getchar();
printf("please input id:");
fgets(s->id,16,stdin);
s->id[strlen(s->id)-1]='\0';
printf("please input sex:");
fgets(s->sex,5,stdin);
s->sex[strlen(s->sex)-1]='\0';
printf("please input cn sorce :");
scanf("%f",&(s->cn));
printf("please input en sorce :");
scanf("%f",&(s->en));
fprintf(pf,"%s %d %s %s %.2f %.2f\n",s->name,s->age,s->id,s->sex,s->cn,s->en);
free(s);
}
fclose(pf);
pf=NULL;
}
void delect(char*ck)
{
FILE*pf=NULL;
pf=fopen("student.txt","r");
char pk;
stu*p=(stu*)malloc(sizeof(stu));
p->next=NULL;
stu*po=p;
while(1)
{
stu*a=(stu*)malloc(sizeof(stu));
a->next=NULL;
p->next=a;
if(fscanf(pf,"%s %d %s %s %f %f",a->name,&(a->age),a->id,a->sex,&(a->cn),&(a->en))==EOF)
{
break;
}
pk=fgetc(pf);
p=a;
}
stu*pd=po;
stu*pg;
fclose(pf);
pf=NULL;
while(po->next!=NULL)
{
pg=po;
if(strcmp(po->next->id,ck)==0)
{
po=po->next;
pg->next=po->next;
free(po);
break;
}
po=po->next;
}
pf=fopen("student.txt","w");
pd=pd->next;
while(pd!=NULL)
{
if(pd->id!=0)
{
fprintf(pf,"%s %d %s %s %.2f %.2f\n",pd->name,pd->age,pd->id,pd->sex,pd->cn,pd->en);
}
pd=pd->next;
}
fclose(pf);
pf=NULL;
}
int show(char*ck)
{
int i=0;
FILE*pf=NULL;
pf=fopen("student.txt","r");
char pk;
stu*p=(stu*)malloc(sizeof(stu));
p->next=NULL;
stu*po=p;
while(1)
{
stu*a=(stu*)malloc(sizeof(stu));
a->next=NULL;
p->next=a;
if(fscanf(pf,"%s %d %s %s %f %f",a->name,&(a->age),a->id,a->sex,&(a->cn),&(a->en))==EOF)
{
break;
}
pk=fgetc(pf);
p=a;
}
fclose(pf);
pf=NULL;
po=po->next;
while(po!=NULL)
{
if(strcmp(po->id,ck)==0)
{
i=1;
printf("name=%s ,age=%d ,id=%s ,sex=%s ,cn=%.2f ,en=%.2f \n",po->name,po->age,po->id,po->sex,po->cn,po->en);
break;
}
po=po->next;
}
return i;
}
void menu_2(void)
{
printf("update information \n");
printf("1.id 2.name \n");
printf("3.en 4.cn \n");
printf("5.sex 6.sex 0.exit \n");
printf("\n");
}
void update_id(char*ck)
{
int i=0;
FILE*pf=NULL;
pf=fopen("student.txt","r");
char pk;
stu*p=(stu*)malloc(sizeof(stu));
p->next=NULL;
stu*po=p;
while(1)
{
stu*a=(stu*)malloc(sizeof(stu));
a->next=NULL;
p->next=a;
if(fscanf(pf,"%s %d %s %s %f %f",a->name,&(a->age),a->id,a->sex,&(a->cn),&(a->en))==EOF)
{
break;
}
pk=fgetc(pf);
p=a;
}
fclose(pf);
pf=NULL;
po=po->next;
stu *pt=po;
while(po!=NULL)
{
if(strcmp(po->name,ck)==0)
{
printf("please update id:");
fgets(po->id,24,stdin);
po->id[strlen(po->id)-1]='\0';
break;
}
po=po->next;
}
pf=fopen("student.txt","w");
while(pt!=NULL)
{
if(pt->age!=0)
{
fprintf(pf,"%s %d %s %s %.2f %.2f\n",pt->name,pt->age,pt->id,pt->sex,pt->cn,pt->en);
}
pt=pt->next;
}
fclose(pf);
pf=NULL;
}
void update_name(char*ck)
{
int i=0;
FILE*pf=NULL;
pf=fopen("student.txt","r");
char pk;
stu*p=(stu*)malloc(sizeof(stu));
p->next=NULL;
stu*po=p;
while(1)
{
stu*a=(stu*)malloc(sizeof(stu));
a->next=NULL;
p->next=a;
if(fscanf(pf,"%s %d %s %s %f %f",a->name,&(a->age),a->id,a->sex,&(a->cn),&(a->en))==EOF)
{
break;
}
pk=fgetc(pf);
p=a;
}
fclose(pf);
pf=NULL;
po=po->next;
stu *pt=po;
while(po!=NULL)
{
if(strcmp(po->id,ck)==0)
{
printf("please update name:");
fgets(po->name,64,stdin);
po->name[strlen(po->name)-1]='\0';
break;
}
po=po->next;
}
pf=fopen("student.txt","w");
while(pt!=NULL)
{
if(pt->age!=0)
fprintf(pf,"%s %d %s %s %.2f %.2f\n",pt->name,pt->age,pt->id,pt->sex,pt->cn,pt->en);
pt=pt->next;
}
fclose(pf);
pf=NULL;
}
void update_cn(char*ck)
{
FILE*pf=NULL;
pf=fopen("student.txt","r");
char pk;
stu*p=(stu*)malloc(sizeof(stu));
p->next=NULL;
stu*po=p;
while(1)
{
stu*a=(stu*)malloc(sizeof(stu));
a->next=NULL;
p->next=a;
if(fscanf(pf,"%s %d %s %s %f %f",a->name,&(a->age),a->id,a->sex,&(a->cn),&(a->en))==EOF)
{
break;
}
pk=fgetc(pf);
p=a;
}
fclose(pf);
pf=NULL;
po=po->next;
stu *pt=po;
while(po!=NULL)
{
if(strcmp(po->id,ck)==0)
{
printf("please update cn:");
scanf("%f",&(p->cn));
break;
}
po=po->next;
}
pf=fopen("student.txt","w");
while(pt!=NULL)
{
if(pt->age!=0)
fprintf(pf,"%s %d %s %s %.2f %.2f\n",pt->name,pt->age,pt->id,pt->sex,pt->cn,pt->en);
pt=pt->next;
}
fclose(pf);
}
void update_en(char*ck)
{
FILE*pf=NULL;
pf=fopen("student.txt","r");
char pk;
stu*p=(stu*)malloc(sizeof(stu));
p->next=NULL;
stu*po=p;
while(1)
{
stu*a=(stu*)malloc(sizeof(stu));
a->next=NULL;
p->next=a;
if(fscanf(pf,"%s %d %s %s %f %f",a->name,&(a->age),a->id,a->sex,&(a->cn),&(a->en))==EOF)
{
break;
}
pk=fgetc(pf);
p=a;
}
fclose(pf);
pf=NULL;
po=po->next;
stu *pt=po;
while(po!=NULL)
{
if(strcmp(po->id,ck)==0)
{
printf("please update en:");
scanf("%f",&(po->en));
break;
}
po=po->next;
}
pf=fopen("student.txt","w");
while(pt!=NULL)
{
if(pt->age!=0)
fprintf(pf,"%s %d %s %s %.2f %.2f\n",pt->name,pt->age,pt->id,pt->sex,pt->cn,pt->en);
pt=pt->next;
}
}
void update_sex(char*ck)
{
FILE*pf=NULL;
pf=fopen("student.txt","r");
char pk;
stu*p=(stu*)malloc(sizeof(stu));
p->next=NULL;
stu*po=p;
while(1)
{
stu*a=(stu*)malloc(sizeof(stu));
a->next=NULL;
p->next=a;
if(fscanf(pf,"%s %d %s %s %f %f",a->name,&(a->age),a->id,a->sex,&(a->cn),&(a->en))==EOF)
{
break;
}
pk=fgetc(pf);
p=a;
}
fclose(pf);
pf=NULL;
po=po->next;
stu *pt=po;
while(po!=NULL)
{
if(strcmp(po->id,ck)==0)
{
printf("please update sex:");
fgets(po->sex,5,stdin);
po->sex[strlen(po->sex)-1]='\0';
break;
}
po=po->next;
}
pf=fopen("student.txt","w");
while(pt!=NULL)
{
if(pt->age!=0)
fprintf(pf,"%s %d %s %s %.2f %.2f\n",pt->name,pt->age,pt->id,pt->sex,pt->cn,pt->en);
pt=pt->next;
}
}
void update_age(char*ck)
{
FILE*pf=NULL;
pf=fopen("student.txt","r");
char pk;
stu*p=(stu*)malloc(sizeof(stu));
p->next=NULL;
stu*po=p;
while(1)
{
stu*a=(stu*)malloc(sizeof(stu));
a->next=NULL;
p->next=a;
if(fscanf(pf,"%s %d %s %s %f %f",a->name,&(a->age),a->id,a->sex,&(a->cn),&(a->en))==EOF)
{
break;
}
pk=fgetc(pf);
p=a;
}
fclose(pf);
pf=NULL;
po=po->next;
stu *pt=po;
while(po!=NULL)
{
if(strcmp(po->id,ck)==0)
{
printf("please update age:");
scanf("%d",&(po->age));
break;
}
po=po->next;
}
pf=fopen("student.txt","w");
while(pt!=NULL)
{
if(pt->age!=0)
fprintf(pf,"%s %d %s %s %.2f %.2f\n",pt->name,pt->age,pt->id,pt->sex,pt->cn,pt->en);
pt=pt->next;
}
}
int main(void)
{
int choice,i,k;
stu*p=(stu*)malloc(sizeof(stu));
p->next=NULL;
menu();
while(1)
{
printf("please input nums:");
scanf("%d",&choice);
switch(choice)
{
case 0:
goto a;
break;
case 1:
add();
break;
case 2:
getchar();
printf("please iput id:");
fgets(p->id,16,stdin);
p->id[strlen(p->id)-1]='\0';
delect(p->id);
break;
case 3:
getchar();
printf("please input student id:");
fgets(p->id,16,stdin);
p->id[strlen(p->id)-1]='\0';
i=show(p->id);
if(!i)
{
printf("select false!\n");
}
break;
case 4:
getchar();
menu_2();
while(1)
{
printf("please input nums:");
scanf("%d",&k);
switch(k)
{
case 0:
goto cp;
break;
case 1:
getchar();
printf("please the id of the student_name:");
fgets(p->name,64,stdin);
p->name[strlen(p->name)-1]='\0';
update_id(p->name);
break;
case 2:
getchar();
printf("please iput the student_name of id:");
fgets(p->id,24,stdin);
p->id[strlen(p->id)-1]='\0';
i=show(p->id);
if(!i)
{
printf("no student!\n");
break;
}
update_name(p->id);
break;
case 3:
getchar();
printf("please iput the student_name of id:");
fgets(p->id,24,stdin);
p->id[strlen(p->id)-1]='\0';
update_cn(p->id);
break;
case 4:
getchar();
printf("please iput the student_name of id:");
fgets(p->id,24,stdin);
p->id[strlen(p->id)-1]='\0';
update_en(p->id);
break;
case 5:
getchar();
printf("please iput the student_name of id:");
fgets(p->id,24,stdin);
p->id[strlen(p->id)-1]='\0';
update_sex(p->id);
break;
case 6:
getchar();
printf("please iput the student_name of id:");
fgets(p->id,24,stdin);
p->id[strlen(p->id)-1]='\0';
update_age(p->id);
break;
}
}
cp:
break;
}
}
a:
free(p);
return 0;
}
会学生管理系统和什么管理系统啊,订餐系统之类的都差不多.
c语言实现简易学生管理系统相关推荐
- Java09-day09【ArrayList(概述、构造方法、常用方法、遍历)、简易学生管理系统】
java零基础入门到精通(2019版)[黑马程序员] 视频+资料:[链接:https://pan.baidu.com/s/1MdFNUADVSFf-lVw3SJRvtg 提取码:zjxs] &qu ...
- c语言字符密码验证码,c语言下的学生管理系统(含密码加密和验证码).docx
c语言下的学生管理系统(含密码加密和验证码).docx #include #include #include #include #include #define N 20void input();// ...
- java用链表做学生系统_C语言链表实现学生管理系统
本文实例为大家分享了C语言链表实现学生管理系统的具体代码,供大家参考,具体内容如下 #include #include #include #include #include #include usin ...
- 【开发细节】用C语言基础写学生管理系统(七)
前情回顾 完成了所有自定义头文件的编写 一.本次目标 完成程序主入口,一一对应功能实现算法,直到所有功能基本上实现 GitHub:https://github.com/ITchujian/Studen ...
- 制作基于springboot的简易学生管理系统(详细)
制作基于springboot的简易学生管理系统(详细) 基于书本与百度创作,内容简易,请多多指教( ̄▽ ̄)/ 设计一个简易学生管理系统 所需环境 创建一个springboot项目 设计数据库 配置Gr ...
- C语言写的学生管理系统
每年都有许多刚刚接触C语言小伙伴门,面对老师布置的学生管理系统感到无从下手.网上也有许多版本大多都比较复杂,可能一些刚刚入门的小伙伴看起来会比较困难.下面是一个完整的学生管理系统.都是用最简单的方法写 ...
- c语言实现的学生管理系统,教你如何玩飞c语言!
教你如何玩飞c语言------学生管理系统篇上(链表篇) 作为编程语种链最底层的OG(元老),相信无论是学Java,python,JS还是其他语种的小伙伴们,都或多或少地听说过我们年长的长辈,c语言! ...
- 使用c语言写一个学生管理系统,学生信息包含姓名/性别/年龄/成绩,可以查改删增...
以下是一个简单的学生管理系统的C语言实现,支持对学生信息进行添加.查询.修改和删除. ```c #include <stdio.h> #include <stdlib.h> # ...
- C#简易学生管理系统
添加3个类,分别实现 IComparer接口,实现对Student类的三个字段的排序. 1.学生类:学号.姓名.年龄 2.请选择:1.添加学生信息.2.删除学生信息 2.查询学生信息. 3.重复的学号 ...
最新文章
- POJ1083 Moving Tables
- sql的加减乘除运算_实现四则运算的一条sql语句
- 二分图最大权匹配算法KM
- RHEL 集群(RHCS)配置小记 -- 文档记录
- 外部表不是预期的格式怎么解决_1分钟拆解:如何将10多个工作表sheet,合并成一张?...
- cudnn7.6.5下载 solitairetheme8_233小游戏下载安装赚钱-233小游戏下载安装最新版v2.29.4.5...
- 20210311 plecs 对传递函数进行波特图分析
- java实现中文语音朗读
- LibreELEC(kodi)安装
- 使用深度图重建世界坐标
- 2021年暑期训练阶段三Day3
- socket服务器针对客户端ip变更的处理办法
- windows下安装maven后运行:mvn help:system报错
- moto XT316 刷机+ROOT权限获取
- PC操作系统使用技巧
- R语言多层桑基图_R语言轻松搞定用户路径桑基图
- 仿微博视频边下边播之封装播放器
- 云南原乡|坐拥腾冲旅游绝佳位置 是旅居养生度假投资首选
- opencv教程CV2模块——图片处理,HSV、色调、亮度调节
- 6个做好网站SEO必不可少的方法
热门文章
- 一张图看懂IaaS, PaaS和SaaS的区别
- 零基础开发一款微信小程序商城
- C语言象棋马的遍历程序,[算法]图算法之骑士遍历问题(象棋中马的遍历问题)分析,C语言实现...
- CST 2022时间如何格式化
- 线性反馈移位寄存器(LFSR)和 Berlekamp-Massey 算法
- 【春招尾声】程序员の井沿理论
- 机器学习笔记一:导论
- codeforces 1546B AquaMoon and Stolen String
- 智慧外链微信小程序源码1.8版本
- 解决java.net.UnknownHostException: XXXX: 未知的名称或服务 at java.net.Inet6AddressI