TechnicalTobi
New Coder
I am working on a project in which data from .bin file have to be transferred to .csv . The data consists of many points each containing 4 values in varying dataformats, them being Time stamp, Pressure, System state and Alarm state.
Unfortunately the same error, being 'too many arguments to function', shows up for every instance of fread and fwrite and I can't manage to find a solution. Any help would be greatly appreciated!
Unfortunately the same error, being 'too many arguments to function', shows up for every instance of fread and fwrite and I can't manage to find a solution. Any help would be greatly appreciated!
#include <stdio.h>
#include <stdlib.h>
int main()
{
char temp;
int size;
int i;
struct data
{
long long Time_stamp;
int Pressure_pa;
char System_state;
char Alarm_state;
};
struct data data_t;
FILE *fp;
fp = fopen("pressureSpike.bin", "rb");
FILE *csv;
csv = fopen("pressureSpike.csv", "w+");
if (fp== NULL)
{
fprintf(stderr, "Data file would not open");
return(-1);
}
fseek(fp, 0, SEEK_END);
size=ftell(fp);
fprintf(stdout, "The size of the file is %d\n", size);
fseek(fp,0,SEEK_CUR);
for (i = 0; i<= feof(fp); i++)
{
fread(&data_t, 8, 4, 1, 1, fp);
printf("Time_stamp is %lld, Pressure is %i in pa, System_state is %c, Alarm_state is %c\n", data_t.Time_stamp, data_t.Pressure_pa);
fwrite(&data_t.Time_stamp, 8, 4, 1, 1, csv);
fwrite(&data_t.Pressure_pa, 8, 4, 1, 1, csv);
fwrite(&data_t.System_state, 8, 4, 1, 1, csv);
fwrite(&data_t.Alarm_state, 8, 4, 1, 1, csv);
}
fclose(fp);
fclose(csv);
fprintf(stdout, "Done reading files\n");
return 0;
}