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 に答える