//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语言读写数据的更多相关文章

  1. R语言读写数据

    R语言读写数据 一般做模型的时候,从外部的excel中读入数据,我现在常用的比较多的是read_csv(file) 读入之前先把excel数据转化成.csv格式 同样的把结果输出来的时候用的是writ ...

  2. R语言读写中文编码方式

    最近遇到一个很头疼的事,就是 R语言读写中文编码方式.在网上找到了一篇博文,谢谢博主的精彩分享,让我很快解决了问题,在此也分享一下 R语言读写数据的方法很多,这里主要是我在使用read.csv/rea ...

  3. .net环境下跨进程、高频率读写数据

    一.需求背景 1.最近项目要求高频次地读写数据,数据量也不是很大,多表总共加起来在百万条上下. 单表最大的也在25万左右,历史数据表因为不涉及所以不用考虑, 难点在于这个规模的热点数据,变化非常频繁. ...

  4. C# .Net 多进程同步 通信 共享内存 内存映射文件 Memory Mapped 转 VC中进程与进程之间共享内存 .net环境下跨进程、高频率读写数据 使用C#开发Android应用之WebApp 分布式事务之消息补偿解决方案

    C# .Net 多进程同步 通信 共享内存 内存映射文件 Memory Mapped 转 节点通信存在两种模型:共享内存(Shared memory)和消息传递(Messages passing). ...

  5. Python 学习 第17篇:从SQL Server数据库读写数据

    在Python语言中,从SQL Server数据库读写数据,通常情况下,都是使用sqlalchemy 包和 pymssql 包的组合,这是因为大多数数据处理程序都需要用到DataFrame对象,它内置 ...

  6. Python中异常和JSON读写数据

    异常可以防止出现一些不友好的信息返回给用户,有助于提升程序的可用性,在java中通过try ... catch ... finally来处理异常,在Python中通过try ... except .. ...

  7. R语言进行数据预处理wranging

    R语言进行数据预处理wranging li_volleyball 2016年3月22日 data wrangling with R packages:tidyr dplyr Ground rules ...

  8. HDFS读写数据块--${dfs.data.dir}选择策略

    最近工作需要,看了HDFS读写数据块这部分.不过可能跟网上大部分帖子不一样,本文主要写了${dfs.data.dir}的选择策略,也就是block在DataNode上的放置策略.我主要是从我们工作需要 ...

  9. win10 svchost.exe (LocalSystemNetworkRestricted)大量读写数据

    博主的笔记本联想Y50开机完毕后会不停滴读硬盘/写硬盘,导致开机后一段时间内无法正常使用电脑(硬盘读写高峰期).打开资源监视器发现是"svchost.exe (LocalSystemNetw ...

随机推荐

  1. 使用hystrix监控时出现java.lang.ClassNotFoundException: com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAsp错误,导致无法启动

    解决方法: 添加依赖 <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId>h ...

  2. k8s搭建链路监控:skywalking

    skywalking架构及简介 官网:https://github.com/apache/skywalking 简介 Java, .NET Core, NodeJS, PHP, and Python ...

  3. [题解]Mail.Ru Cup 2018 Round 1 - A. Elevator or Stairs?

    [题目] A. Elevator or Stairs? [描述] Masha要从第x层楼去第y层楼找Egor,可以选择爬楼梯或者坐直升电梯.已知爬楼梯每层需要时间t1:坐直升电梯每层需要时间t2,直升 ...

  4. 都在用神器,只有你还在死磕excel做分析

    一.excel数据分析工具_EXCE弱点 EXCEL一直是非常流行的个人计算机数据处理工具,它可以处理多种多样的数据,操作非常简单,支持丰富的函数.统计图表,在工作中更是非常得力的生产力工具.然而随着 ...

  5. Guided Anchoring:在线稀疏anchor生成方案,嵌入即提2AP | CVPR 2019

    Guided Anchoring通过在线生成anchor的方式解决常规手工预设anchor存在的问题,以及能够根据生成的anchor自适应特征,在嵌入方面提供了两种实施方法,是一个很完整的解决方案   ...

  6. vim编辑以及脚本编程练习

    转至:http://www.178linux.com/88128 vim编辑器的使用总结: vim在工作过程当中有三种模式:编辑模式.输入模式.末行模式. 1.编辑模式:即命令模式,键盘操作常被理解为 ...

  7. KETTLE使用中的错误集锦

    1.违反唯一主键约束条件:问题是表中有俩个主键,将备用主键替换成真正的主 键或者是没有对数据做出处理加这句话and cft.DEL_FLAG!='1'或者要到的库有此数据 2.field 某列 is ...

  8. 【有奖调研】来,聊聊TTS音色定制这件事儿

    音色个性化定制,一个能让文字转语音服务(TTS)在用户交互过程中注入温度的技术. 文能在营销及内容交付中让品牌保持一致性,武能让开发者"音"量加持,创新开发. 这个100%钢铁纯技 ...

  9. JZ-027-字符串的排列

    字符串的排列 题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则按字典序打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和c ...

  10. js数组用法

    去面试的时候问到我一个问题,你能说出来多少种数组的方法跟用法,我当时只说出来十一个,回来以后才想起来还有很多种,现在整理一下,没有排名,想起那个写那个 1:forEach 从头遍历数组,没有返回值,有 ...