C语言实践——学生信息管理
这是本人做的第一个实践项目,用的知识都是书上有的,没有很多很复杂的知识
同时因为没有学习 C语言 图形方面的知识,所以界面做得很丑,暂时先这样吧
源文件:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "student.h" void main()
{
int num_order;
char c; num_order = msg();//输出相关信息,获取相关操作 while( num_order!=1 && num_order!=2 && num_order!=3)
{
printf("请重新输入正确参数:\n");
scanf("%d",&num_order);
} switch( num_order )
{
case 1: from_file(0); break;//查询
case 2: input_(); break;//录入
case 3: from_file(1); break;//修改
} c = getchar();//用于接受上一个回车符
printf("\n是否执行其他操作?\n是/Y、否/N\n");
c = getchar();
while( c == 89 || c == 121 )
{
printf("请输入相关参数\n");
scanf("%d",&num_order);
switch( num_order )
{
case 1: from_file(0); break;//查询
case 2: input_(); break;//录入
case 3: from_file(1); break;//修改
}
c = getchar();
printf("\n是否执行其他操作?\n是/Y、否/N\n");
c = getchar();
} }
Student.h 头文件:
#include <stdio.h>
#include <string.h>
#include <stdlib.h> int msg();//信息提示窗口
void input_();//录入相关信息
void save_files( struct Student_info *p );//保存内容至文件
void print_( struct Student_info *p, int n );//输出内容到屏幕
void from_file( int flag );//读取文件内容
void change_info( struct Student_info *p, int loop );//修改相关内容
void sort_info(struct Student_info *p);//排序 struct Student_info
{
char name[10];
int id;
int age;
char adress[30];
}; int num_stud; int msg()//信息提示窗口
{
int n; printf("\t\t\t\t学生管理系统\n\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╰═════════════════╯\n"); scanf("%d",&n);
return(n);
} void input_()//录入相关信息
{
int i;
struct Student_info *p,*into_save; system("cls"); printf("学生信息录入系统:\n");
printf("请输入想要录入信息的学生人数\n"); scanf("%d",&num_stud);
if((into_save = p = ( struct Student_info *)malloc( num_stud * sizeof( struct Student_info ))) == NULL )
printf("创建空间失败!\n");
else
printf("依次输入学生学号 姓名 年龄 地址\n");
for( i = 0; i < num_stud ; i++, p++ )
{
scanf( "%d %s %d %s", &p->id, p->name, &p->age, p->adress);
} save_files( into_save );
} void save_files( struct Student_info *p )//内容保存
{
int i;
FILE *fp;
if( (fp = fopen( "stud.dat", "ab" )) != NULL )
{
for( i = 0; i < num_stud; i++, p++ )
{
fwrite( p , sizeof(struct Student_info), 1, fp);
}
fclose( fp );
printf( "信息录入完成!\n" );
}
else if( (fp = fopen( "stud.dat", "wb" )) == NULL )
{
printf( "文件创建失败!\n");
exit(0);
}
else
{
for( i = 0; i < num_stud; i++, p++ )
{
fwrite( p , sizeof(struct Student_info), 1, fp);
}
fclose( fp );
printf( "信息录入完成!\n" );
}
} void print_( struct Student_info *p, int n )//输出屏幕
{
int i;
printf( "学号\t姓名\t年龄\t地址\n\n");
for( i = 0; i < n ; i++, p++ )
{
printf( "%-4d %7s %6d %8s\n", p->id, p->name, p->age, p->adress);
}
printf("\n");
} void from_file( int flag )//读取文件内容
{
FILE *fp;
struct Student_info temp;
struct Student_info *p,*into_print,*first;
int i = 0;
int loop = 0; system("cls");
printf("\t学生信息查询 \n"); if((fp = fopen("stud.dat","rb")) == NULL)
{
printf( "文件信息不存在\n" );
exit(0);
} while( !feof(fp) )
{
fread( &temp, sizeof(struct Student_info), 1, fp);
loop++;
}
loop-=1;//获取文件中内容个数 rewind(fp);
first = into_print = p = (struct Student_info *)malloc(loop*sizeof(struct Student_info));
for( i = 0; i < loop; i++, p++ )
{
fread( p, sizeof(struct Student_info), 1 ,fp);
} print_( into_print, loop ); if( flag == 0 )
{
free( first );
first = into_print = p = NULL;
}
else
{
change_info( first, loop );
}
fclose(fp);
} void change_info( struct Student_info *p, int loop )
{
int n,i;
struct Student_info *t1,*t2;
FILE *fp; printf("请输入要修改学生信息的学号:\n");
scanf("%d",&n);
t2 = t1 = p; for( i = 0; i < loop; i ++, t1++ )
{
if( t1->id == n)
break;
}
scanf( "%d %s %d %s", &t1->id, t1->name, &t1->age, t1->adress); if( ( fp = fopen( "stud.dat", "wb") ) == NULL )
{
printf("文件写入错误!\n");
}
else
{
for( i = 0; i < loop; i ++, p++ )
{
fwrite( p, sizeof(struct Student_info), 1, fp );
}
}
fclose(fp);
printf("修改成功!\n");
free(t2);
}
运行界面:
1.首页

2.录入界面

3.查询界面

4.修改界面

注意看学号 102 的信息 已经改变

附上文件的链接:
链接:http://pan.baidu.com/s/1sjjSpy9 密码:kowr
C语言实践——学生信息管理的更多相关文章
- 《程序设计语言——实践之路(英文第三版)》【PDF】下载
<程序设计语言--实践之路(英文第三版)>[PDF]下载链接: https://u253469.pipipan.com/fs/253469-230382234 内容简介 <程序设计语 ...
- 《程序设计语言——实践之路【PDF】下载
<程序设计语言--实践之路[PDF]下载链接: https://u253469.pipipan.com/fs/253469-230382240 内容简介 <程序设计语言--实践之路(第3版 ...
- 【学员管理系统】0x02 学生信息管理功能
[学员管理系统]0x02 学生信息管理功能 写在前面 项目详细需求参见:Django项目之[学员管理系统] Django框架大致处理流程 捋一下Django框架相关的内容: 浏览器输入URL到页面展示 ...
- 《程序设计语言——实践之路》【PDF】下载
程序设计语言--实践之路>[PDF]下载链接: https://u253469.pipipan.com/fs/253469-230382240 内容简介 本书在美国大学已有使用了十余年,目前被欧 ...
- R语言︱H2o深度学习的一些R语言实践——H2o包
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- R语言H2o包的几个应用案例 笔者寄语:受启发 ...
- Problem X: C语言习题 学生成绩输入和输出
Problem X: C语言习题 学生成绩输入和输出 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 4722 Solved: 2284[Submit] ...
- Laravel之简单的学生信息管理平台
laravel框架写的简易版的学生信息管理平台,贯穿了laravel的控制器.视图.模板.模型.中间件.路由规则的使用. 页面是使用BootStrap前端框架搭建 使用laravel实现了增删改查的功 ...
- YTU 2429: C语言习题 学生成绩输入和输出
2429: C语言习题 学生成绩输入和输出 时间限制: 1 Sec 内存限制: 128 MB 提交: 1897 解决: 812 题目描述 编写一个函数print,打印一个学生的成绩数组,该数组中有 ...
- vue实现简单学生信息管理案例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
随机推荐
- phpStorm注册马码
phpstorm已经升级到10.0,原注册码失效,10.0注册方法:注册时选择“License server”输入 http://idea.lanyus.com/ 此工具类工具一直没有让我失望
- WindowsForm 公共控件 菜单和工具栏
公共控件 菜单栏 状态栏 布局 公共控件 textbox: text属性:用于获取或 ...
- javaweb一周总结(菜鸟)
我的试用期开始了. 这是我的第一篇博客,这也是我作为java工程师的第六天,主要是为了记录一周内出现的问题以及一些工作上的解答,吐槽一句工作的确和想的不一样之后直接记录下吧. 由于拥有工作平台看不到底 ...
- javascript中的with
with语句主要用来对一个对象操作多个属性,使代码简洁易读. 语法: with(object) statements object是新的默认对象,statements是一个或多个语句 例如: var ...
- JS基础如何理解对象
这几天跟几个同事聊天发现他们对javascript什么时候该用new都不是很了解. 1.javascript的function什么时候该new什么时候不该new?我觉得主要的问题还是集中在javasc ...
- php or || 和 and &&
追溯代码时遇到这个坑,一直是略有懵懂,那就填了这个坑. 1 if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = BASEPATH.' ...
- IntentService的使用
1.为什么需要IntentService 是LocalService的包装类,简便Service的创建,使用的是startService(),也就是访问者退出Service不会消失. 2.实现原理 步 ...
- PYthon成长之路第一篇(1)__字符串初识
今天一起走进python的代码世界,一起领悟python的魅力 在很多学习python的书中都会以 print “Hello,world!” 这样的而一个程序为开始,那么其中的 hello,worl ...
- web 之MVC
MVC 把一个应用的输入.处理.输出流程按照Model, View, Controller 的方式进行分离,这样一个应用被分为三层:模型层.视图层.控制层. 1.View 2.Controller 在 ...
- Robot Framework语法学习(一)
Robot Framework语法学习: 一.变量的声明.赋值与使用 1.变量标识符:每个变量都可以用 变量标识符 ${变量名} 来表示. 2.变量声明:可以在TestSuite上点右键或者在Edi ...