读取文件内容
来源:互联网 发布:股票自动化交易编程 编辑:程序博客网 时间:2024/06/06 19:19
/*
读取文件内容
*/
#include <stdio.h>
#include <stdlib.h>#define N 30
typedef struct date_order
{
int year;
int month;
int day;
}DATE;
typedef struct student
{
long studentID;
char studentName[10];
char studentSex;
DATE birthday;
int score[4];
float aver;
}STUDENT;
int ReadfromFile(STUDENT stu[],int m)
{
FILE *fp;
int i,j;
if((fp = fopen("score.txt","r")) == NULL)
{
printf("Fialure to open score.txt!\n");
exit(0);
}
for(i = 0;!feof(fp);i++)
{
fscanf(fp,"%10ld",&stu[i].studentID);
fscanf(fp,"%8s",stu[i].studentName);
fscanf(fp," %c",&stu[i].studentSex);
fscanf(fp,"%6d/%2d/%2d",&stu[i].birthday.year,
&stu[i].birthday.month,
&stu[i].birthday.day);
for(j=0;j<m;j++)
{
fscanf(fp,"%4d",&stu[i].score[j]);
}
fscanf(fp,"%f",&stu[i].aver);
}
fclose(fp);
printf("Total student is %d.\n",i-1);
return i-1;
}
void PrintScore(STUDENT stu[],int n,int m)
{
int i,j;
for(i=0;i<n;i++)
{
printf("%10ld %8s %3c %6d /%02d /%02d",
stu[i].studentID,stu[i].studentName,stu[i].studentSex,
stu[i].birthday.year,stu[i].birthday.month,stu[i].birthday.day);
for(j = 0;j<m;j++)
{
printf("%4d",stu[i].score[j]);
}
printf("%6.1f\n",stu[i].aver);
}
}
int main()
{
STUDENT stu[N];
int n;
n = ReadfromFile(stu,4);
PrintScore(stu,n,4);
return 0;
}
阅读全文
1 0
- 读取xml文件内容
- 文件内容读取
- 读取网络文件内容
- Shell读取文件内容
- 读取Excel文件内容
- FileReader读取文件内容!
- C++读取文件内容
- QTextStream 读取文件内容
- 读取文件内容
- 读取excel文件内容
- 读取properties文件内容
- 文件内容的读取
- 读取txt文件内容
- C读取文件内容
- QTextStream读取文件内容
- 读取pdf文件内容
- 读取写入文件内容
- 读取文件内容
- 将Unity官方射击游戏 Space Shooter 改为实时对战小游戏,使用天梯实时对战服务(NanoLink)
- ANR&OOM
- python实现换位加密算法
- pm2的那些坑
- Cordova插件开发
- 读取文件内容
- Android-应用启动过程
- 简述装饰模式实现思想
- Android控件三(ProgressBar 进度条)
- Android—常用控件(一)文本控件
- java ftp 文件下载
- cookie和session的思考
- 6月读书《有效的管理者》笔记
- Mac 配置angular-cli环境