从不兼容的指针类型传递'fprintf'的argument1时出错。 C

时间:2013-03-21 15:50:26

标签: c data-structures

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

#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

            }
        }
    }
}

1 个答案:

答案 0 :(得分:8)

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