文件读取,fscanf()的使用问题!
#include<conio.h>#include<stdio.h>
#include<bios.h>
#include<stdlib.h>
#include"graphics.h"
#include"time.h"
struct timdata{
int year;
int mon;
int day;
int wday;
int hour;
int min;
int sec;
float data;
};
void main(){
FILE*fp;
int i;
struct timdata da[20];
fp=fopen("data.txt","r");
for(i=0;i<20;i++){
fscanf(fp,"%d/%d/%d%d%d:%d:%d%.2f\n",&da[i].year,&da[i].mon,&da[i].day,&da[i].wday,&da[i].hour,&da[i].min,&da[i].sec,&da[i].data);
printf("%d/%d/%d %d %d:%d:%d %.2f\n",da[i].year,da[i].mon,da[i].day,da[i].wday,da[i].hour,da[i].min,da[i].sec,da[i].data);
}
fclose(fp);
getch();
}这是我的读取程序!
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
2013/8/24 6 9:59:46 4.16
这是文件数据,保存为data。txt。。运行后为读取后的数据只有第一行的前七个是正确的,后面的都是错的???大神求解释!