//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); }

  

最新文章

  1. crontab用法与实例
  2. angularJs中ui-router的使用
  3. 【php】中【event】之实现方式
  4. HDU ACM 1025 Constructing Roads In JGShining&amp;#39;s Kingdom-&amp;gt;二分求解LIS+O(NlogN)
  5. 【Python&amp;Sort】QuickSort
  6. Python抓取成都房价信息
  7. 201521123051《Java程序设计》第六周学习总结
  8. cocos对lua代码加密
  9. Scrapy爬虫框架第四讲(Linux环境)
  10. 复杂度定义 The Definition of Complexity
  11. 分别用命令行、NetBeans IDE 8.2实现firstcup 项目部署
  12. oracle工具sqluldr2和sqlldr的使用
  13. 【java】之算法复杂度o(1), o(n), o(logn), o(nlogn)
  14. Windows Server 2016-Active Directory域服务端口汇总
  15. pl-svo代码解读
  16. pc-H5 适配方案
  17. WAF Bypass数据库特性(Access探索篇)
  18. python关于时间的计算,time模块
  19. 在Linux(CentOS)中安装.netcore SDK
  20. HDU 3436 Queue-jumpers

热门文章

  1. centos7.+系统,mysql主从部署
  2. 攻防世界Web_easytornado
  3. [Java]Thinking in Java 练习2.10
  4. [题解]UVA10129 Play on Words
  5. 学习Spring5必知必会(6)~Spring DAO
  6. 移动BI,移动报表平台
  7. 给bootstrap-table填坑
  8. 关于WinForm布局那些事情
  9. SpringMVC教程--eclipse中使用maven创建springMVC项目
  10. c语言怎么避免打印空数据?