Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C Why is fread and fwrite giving error 'containing too many arguments'?

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!

#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; }
 
Back
Top Bottom