cfileioscanf

c - reading a specific column in data file


So I created a data file like so:

for(size_t n = ...;...;...){
    //do some stuff
    double mean_value = ...
    double min_value = ...
    double max_value = ...

    FILE *fp = fopen(OUTPUT_FILE,"a+");
    fprintf(fp,"%d %lf %lf %lf\n",n,mean_value, min_value, max_value);
    fclose(fp);
}

And now i want to read the mean_values that I've written...

FILE *fp = fopen(OUTPUT_FILE,"a+");
double *means = malloc(...);
for(size_t i = 0; ...; ...){
    fscanf(fp,"%*d %lf %*lf %*lf\n", &means[i]);
}
//more stuff
fprintf(fp,...);
fclose(fp);

And gcc complains about that:

warning: use of assignment suppression and length modifier together in gnu_scanf format [-Wformat=]

fscanf(fp,"%*d %lf %*lf %*lf\n", &means[i]);

         ^

And I'm not sure what it's trying to tell me, here.


Solution

  • The length specifier (namely l in lf) in the format string is intended to indicate the size of the receiving parameter in case it is assigned, while f tells how the input should look like. It means that specifying the length for the fields which are suppressed is meaningless, and your compiler is just trying to make sure you haven't mistakenly typed * instead of %. Just remove the l from the suppressed fields.