C - read and store data file for further calculations

后端 未结 3 1579
谎友^
谎友^ 2021-01-28 09:33

I normally use R, and have a lot of trouble understanding C. I need to read and store a data file, shown below, so that I can perform calculations on the data.

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 10:10

    An example for writing:

    FILE *fp;
    fp=fopen("c:\\test.bin", "wb");
    char x[10]="ABCDEFGHIJ";
    fwrite(x, sizeof(x[0]), sizeof(x)/sizeof(x[0]), fp);
    

    (write declaration)

    size_t fwrite(const void *ptr, size_t size_of_elements, size_t number_of_elements, FILE *a_file);
    

    If you were to read,

    size_t fread(void *ptr, size_t size_of_elements, size_t number_of_elements, FILE *a_file);
    

提交回复
热议问题