用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 ...
随机推荐
- Kubeadm部署-Kubernetes-1.18.6集群
环境配置 IP hostname 操作系统 10.11.66.44 k8s-master centos7.6 10.11.66.27 k8s-node1 centos7.7 10.11.66.28 k ...
- unity3d导出xcode项目使用afnetworking 3框架导致_kUTTagClassMIMEType 问题解决方案
http://blog.csdn.net/huayu_huayu/article/details/51781953 (参考链接) Undefined symbols for architecture ...
- 巧用阿里云同步k8s.gcr镜像
问题 谷歌云镜像仓库:k8s.gcr.io 镜像拉取不下来 阿里云操作配置 注册阿里云账号:点击注册 右上角点击"控制台" 点击左上角 选择"容器镜像服务" 第 ...
- Renix签名字段详解——网络测试仪实操
一.签名字段简介 在添加/修改流量时,会有一个签名字段选项 (1)勾选以后,RENIX软件在发流时,会把每个报文的Payload(净荷)的最后18字节修改为特殊的值,用来统计流的时延.丢包等内容 (2 ...
- 【windows 操作系统】【CPU】用户模式和内核模式(用户层和内核层)
所有的现代操作系统中,CPU是在两种不同的模式下运行的: 注意以下内容来自微软: windows用户模式和内核模式 运行 Windows 的计算机中的处理器有两个不同模式:用户模式 和内核模式 . 用 ...
- omnet++:使用教程
学习自:(6条消息) omnet++ 快速入门 | 计算机网络仿真 | omnet++ 入门教程_叶局长的博客-CSDN博客 1.使用omnet仿真的一般步骤 主要有3步: 使用ned(network ...
- 快速构建 React 开发环境
使用 create-react-app 快速构建 React 开发环境 create-react-app 是来自于 Facebook,通过该命令我们无需配置就能快速构建 React 开发环境. cre ...
- python面试_总结01_概念和内置高阶函数
- 简答题 1.请谈谈Python中is 和 == 的区别(代码演示) is用于比较两个变量是否引用了同一个内存地址,is表示的是对象标识符(object identity),作用是用来检查对象的标识 ...
- (五)目标检测算法之Faster R-CNN
系列博客链接: (一)目标检测概述 https://www.cnblogs.com/kongweisi/p/10894415.html (二)目标检测算法之R-CNN https://www.cnbl ...
- 微信小程序防抖
https://www.cnblogs.com/daviddd/p/12470480.html 1:wxml:设置一个按钮 <button type="primary" bi ...