这就是我到目前为止所拥有的。我需要读取文件day.txt,计算文件的行数
#include "stdio.h"
#include "stdlib.h"
#define MAX_LINE_LENGTH
struct earthquake_t{
float lat;
float lng;
float dep;
float mag;
};
FILE* fid;
int main(void)
{
double lat,lng dep,mag;
double userminlat,userminlng,usermaxlat,usermaxlng,minlat,minlng,maxlat,maxlng,i, ch,line;
struct earthquake_t *earthquake;
fid=fopen("day.txt","r");
while (!feof(fid))
{ /*Need help counting lines*/
count = fscanf(fid," %lf %lf %lf\n",&lng,&lat,&dep,&mag);
/* count tell you how many of the % fields were matched,
and you need to make sure all three were found to avoid blank lines*/
if (count ==3)
{
line ++;
}
}
fseek(fid,1,SEEK_SET);
print("%d\n",sizeof(struct earthquake_t));
earthquake = (struct earthquake_t *)malloc(sizeof(struct earthquake_t)*line);
for (i=0;i<line;i++)
{
fscanf("fid,%lf %lf %lf\n",&lng,&lati,&elevi)
earthquake[i].lat=lat;
earthquake[i].lng=lng;
earthquake[i].dep=dep;
earthquake[i].mag=mag;
/*Setting the min and max values for latitude and longatidue*/
if(earthquake[i].lng >maxlng)
{
maxlng = earthquake[i].lng;
}
if(earthquake[i].lng >minlng)
{
minlng = earthquake[i].lng;
}
if(earthquake[i].lat >maxlat)
{
maxlat = earthquake[i].lat;
}
if(earthquake[i].lat >minlat)
{
minlat = earthquake[i].lat;
}
}