用C语言读写数据
//1-5题
#include "stdio.h"
typedef struct
{
char name[10];//姓名
int subject1,subject2,subject3;//科目1,2,3
long int sno;//学号
}student;
int InputTerm(student *stu)//在终端输入数据并每人的计算平均分
{
int i=0;
while (i<5)
{
printf("Pls input name,subject1,subject2,subject3 and student No\n");
scanf("%s\t%d\t%d\t%d\t%ld",&stu[i].name,&stu[i].subject1,&stu[i].subject2,&stu[i].subject3,&stu[i].sno);
printf("Average of %s is:%d\n",stu[i].name,(stu[i].subject1,stu[i].subject2,stu[i].subject3)/3);
i++;
}
return 1;
} int InputDataTxt(student *stu)//输出到txt文件
{
int i=0;
printf("Input 5 student score\n");
FILE *fd=fopen("data.txt","w");
if (fd==NULL)
return 0;
while (i<5)
{
scanf("%s\t%d\t%d\t%d\t%ld",&stu[i].name,&stu[i].subject1,&stu[i].subject2,&stu[i].subject3,&stu[i].sno);
fprintf(fd,"%s\t%d\t%d\t%d\t%ld\n",stu[i].name,stu[i].subject1,stu[i].subject2,stu[i].subject3,stu[i].sno);
i++;
}
fclose(fd);
return 1;
}
int ReadData(student *stu)//从文本文件中读数据
{
FILE *fd=fopen("data.txt","r");
if (fd==NULL)
return 0;
int i=0;
while(fscanf(fd,"%s\t%d\t%d\t%d\t%ld",&stu[i].name,&stu[i].subject1,&stu[i].subject2,&stu[i].subject3,&stu[i].sno)!=EOF)
{
printf("%s\t%d\t%d\t%d\t%ld\n",stu[i].name,stu[i].subject1,stu[i].subject2,stu[i].subject3,stu[i].sno);
i++;
}
fclose(fd);
return 1;
}
int ReadDataBin(student *stu)//从二进制文件中读数据
{
FILE *fd=fopen("databin","rb");
if (fd==NULL)
return 0;
int i=0;
while(fscanf(fd,"%s\t%d\t%d\t%d\t%ld",&stu[i].name,&stu[i].subject1,&stu[i].subject2,&stu[i].subject3,&stu[i].sno)!=EOF)
{
printf("%s\t%d\t%d\t%d\t%ld\n",stu[i].name,stu[i].subject1,stu[i].subject2,stu[i].subject3,stu[i].sno);
i++;
}
fclose(fd);
return 1;
}
int InputDataBin(student *stu)//输入到二进制文件
{
int i=0;
printf("Input 5 student score\n");
FILE *fd=fopen("databin","wb");
if (fd==NULL)
return 0;
while (i<5)
{
scanf("%s\t%d\t%d\t%d\t%ld",&stu[i].name,&stu[i].subject1,&stu[i].subject2,&stu[i].subject3,&stu[i].sno);
fprintf(fd,"%s\t%d\t%d\t%d\t%ld\n",stu[i].name,stu[i].subject1,stu[i].subject2,stu[i].subject3,stu[i].sno);
i++;
}
fclose(fd);
return 1;
} void main()
{
student stu[5];
InputTerm(stu);
//InputData(stu);
//ReadData(stu);
//InputDataBin(stu);
//ReadDataBin(stu); }
用C语言读写数据的更多相关文章
- R语言读写数据
R语言读写数据 一般做模型的时候,从外部的excel中读入数据,我现在常用的比较多的是read_csv(file) 读入之前先把excel数据转化成.csv格式 同样的把结果输出来的时候用的是writ ...
- R语言读写中文编码方式
最近遇到一个很头疼的事,就是 R语言读写中文编码方式.在网上找到了一篇博文,谢谢博主的精彩分享,让我很快解决了问题,在此也分享一下 R语言读写数据的方法很多,这里主要是我在使用read.csv/rea ...
- .net环境下跨进程、高频率读写数据
一.需求背景 1.最近项目要求高频次地读写数据,数据量也不是很大,多表总共加起来在百万条上下. 单表最大的也在25万左右,历史数据表因为不涉及所以不用考虑, 难点在于这个规模的热点数据,变化非常频繁. ...
- C# .Net 多进程同步 通信 共享内存 内存映射文件 Memory Mapped 转 VC中进程与进程之间共享内存 .net环境下跨进程、高频率读写数据 使用C#开发Android应用之WebApp 分布式事务之消息补偿解决方案
C# .Net 多进程同步 通信 共享内存 内存映射文件 Memory Mapped 转 节点通信存在两种模型:共享内存(Shared memory)和消息传递(Messages passing). ...
- Python 学习 第17篇:从SQL Server数据库读写数据
在Python语言中,从SQL Server数据库读写数据,通常情况下,都是使用sqlalchemy 包和 pymssql 包的组合,这是因为大多数数据处理程序都需要用到DataFrame对象,它内置 ...
- Python中异常和JSON读写数据
异常可以防止出现一些不友好的信息返回给用户,有助于提升程序的可用性,在java中通过try ... catch ... finally来处理异常,在Python中通过try ... except .. ...
- R语言进行数据预处理wranging
R语言进行数据预处理wranging li_volleyball 2016年3月22日 data wrangling with R packages:tidyr dplyr Ground rules ...
- HDFS读写数据块--${dfs.data.dir}选择策略
最近工作需要,看了HDFS读写数据块这部分.不过可能跟网上大部分帖子不一样,本文主要写了${dfs.data.dir}的选择策略,也就是block在DataNode上的放置策略.我主要是从我们工作需要 ...
- win10 svchost.exe (LocalSystemNetworkRestricted)大量读写数据
博主的笔记本联想Y50开机完毕后会不停滴读硬盘/写硬盘,导致开机后一段时间内无法正常使用电脑(硬盘读写高峰期).打开资源监视器发现是"svchost.exe (LocalSystemNetw ...
随机推荐
- erange.heetian.com 回显任意账号
首先获取你想登录ID的REG标识符,例如合天课程专家 获取标识符ba84d3c3-a4a1-4cd2-a00d-2f5722ee86a2 一般用户前缀为REG,这个肯定是管理员之类的= =.. ...
- 第三章 in,not in 的理解,limit限制结果集
IN 运算符用来判断表达式的值是否位于给出的列表中:如果是,返回值为 1,否则返回值为 0.NOT IN 的作用和 IN 恰好相反,NOT IN 用来判断表达式的值是否不存在于给出的列表中:如果不是 ...
- 【论文考古】联邦学习开山之作 Communication-Efficient Learning of Deep Networks from Decentralized Data
B. McMahan, E. Moore, D. Ramage, S. Hampson, and B. A. y Arcas, "Communication-Efficient Learni ...
- 【基础篇】js对本地文件增删改查--删
前置条件: 1. 本地有安装node,点击传送门 项目目录: 1. msg.json内容 { "data": [ { "id": 1, "name&q ...
- node + express 搭建服务器,修改为自动重启服务器
1.使用express搭建一个项目,步骤如下(安装node步骤已省略) a.全局安装express-generator和express npm i express-generator -g npm i ...
- [题解]UVA10986 Sending email
链接:http://vjudge.net/problem/viewProblem.action?id=24941 描述:n个点,m条边的无向图,寻找从S到T的最短路. 思路:基础的单源点最短路 用Di ...
- C++ 派生类函数重载与虚函数继承详解
目录 一.作用域与名字查找 1.作用域的嵌套 2.在编译时进行名字查找 3.名字冲突与继承 4.通过作用域运算符来使用隐藏的成员 二.同名函数隐藏与虚函数覆盖 1.几种必须区分的情况 2.一个更复杂的 ...
- SQL Server Cross/Outer Apply
SQL Server2005引入了APPLY运算符,它非常像连接子句,它允许两个表达式直接进行连接,即将左/外部表达式和右/内部表达式连接起来. CROSS APPLY(类比inner join)和O ...
- kubernetes配置后端存储 rook-ceph
一 Rook概述 1.1 Ceph简介 Ceph是一种高度可扩展的分布式存储解决方案,提供对象.文件和块存储.在每个存储节点上,将找到Ceph存储对象的文件系统和Ceph OSD(对象存储守护程序)进 ...
- WPS:Excel删除指定行以后的所有行
首先定位到你的1000行,然后选中第1000行按住Shift,再同时按住Ctrl加向下的方向键,最后删除即可了.