I'm trying to use fscanf
to read in data, and part of the input is a float followed by the letter 'e'
, for example, 41.72elapsed
. When writing the strng for fscanf
, I attempted to use "%felapsed"
, but this doesn't work, as %fe
is its own format specifier. How would I read this in using fscanf
?
edit: Here is the code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define CHAR_MAX 1024
int main(int argc, char **argv)
{
FILE *file_in = fopen(argv[1], "r+");
char out_name[CHAR_MAX];
strcpy(out_name, argv[1]);
strcat(out_name, ".csv");
FILE *csv_out = fopen(out_name, "w");
int minutes;
float seconds;
fprintf(csv_out, "Trial #, Execution Time\n");
for (int i = 0; fscanf(file_in, "%*fuser %*fsystem %d:%felapsed %*d%%CPU (%*davgtest+%*davgdata %*dmaxresident)k\n%*dinputs+%*doutputs (%*dmajor+%*dminor)pagefaults %*dswaps\n", &minutes, &seconds) == 2; i++) {
fprintf(csv_out, "%d, %d:%.2f\n", i, minutes, seconds);
};
return 0;
}
Here is some sample input:
283.97user 0.69system 1:13.77elapsed 385%CPU (0avgtext+0avgdata 107472maxresident)k
0inputs+4616outputs (0major+9550minor)pagefaults 0swaps
287.87user 0.35system 1:14.41elapsed 387%CPU (0avgtext+0avgdata 107328maxresident)k
0inputs+4616outputs (0major+9524minor)pagefaults 0swaps