0

这是我到目前为止所拥有的。唯一的构建问题是第 95 行,即最后一行代码。我正在尝试计算文件中的行数,然后从数据构建数组并从用户输入中显示最大值和最小值的数组。

#include "stdio.h"
#include "stdlib.h"



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,                      ch,line,count
    struct earthquake_t *earthquake;
    int i;


    fid=fopen("day.txt","r");

    while (!feof(fid))
    {

         line = fscanf(fid,"%lf, %lf, %lf, %lf\n",&lng,&lat,&dep,&mag);
         count = fscanf(fid," %lf %lf %lf %lf\n",&lng,&lat,&dep,&mag);


        if (count ==4)
        {
             line ++;
        }
    }

    fseek(fid,1,SEEK_SET);
    printf("%d\n",sizeof(struct earthquake_t));          
    earthquake = (struct earthquake_t *)malloc(sizeof(struct earthquake_t)*line);

    for (i=0;i<line;i++)
    {          
        sscanf("fid", "%lf %lf %lf %lf\n",&lng,&lat,&dep,&mag,
        earthquake[i].lat,
        earthquake[i].lng,
        earthquake[i].dep,
        earthquake[i].mag);

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

    } 



    printf("Longitude is between %f and %f\n",minlng,maxlng);
    printf("Latitude is between %f and %f\n\n",minlat,maxlat);
    printf("Give a value for min longitude: ");
    scanf("%d",userminlng);
    printf("Give a value for max longitude: ");
    scanf("%d",usermaxlng);
    printf("Give a value for min latitude: ");
    scanf("%d",userminlat);
    printf("Give a value for max latitude: ");
    scanf("%d",usermaxlat);


    FILE *fid2;
    fid2=fopen("subset.txt","w");

    for (i=0;i<line;i++)
    {     
        if((earthquake[i].lng > userminlng) && (earthquake[i].lng < usermaxlng))
        {    
            if((earthquake[i].lat > userminlat) && (earthquake[i].lat < userminlat))
            {
                fprintf( "subset.txt" ,"%f,%f,%f,%f \n", earthquake[i].lat,              earthquake[i].lng, earthquake[i].dep, earthquake[i].mag); //error

            }
        }
    }
}
4

1 回答 1

8

fprintfFILE *指针作为其第一个参数。在这种情况下,您可能想传入fid2.

于 2013-03-21T15:51:41.617 回答