首页 > 解决方案 > C中二进制文件的动态存储

问题描述

Participant *readRankingList (const char *filename, int *length) {
    length = 0;
    int i=0;
    
    FILE *fp;
    fp = fopen(filename, "rb");
    Participant *list;
    
    if (fp == NULL) {
        fprintf(stderr, "*** open of %s failed ***\n", filename);
        return 0;
    }
    
    length = fread((void *)list, sizeof(Participant), LIST_LEN, fp);
    
    while(fread(list, sizeof(length), 1, fp)>0){
        list[i]=list;
        i++; 
    }
    
   
    free(list);
    fclose(fp);
    *length = i;
    return list;
}

我有一个二进制文件,我在这部分打开它。现在我想用动态存储来存储它。目前我得到一个

Warning : assignment makes pointer from intefer without a cast

Error: incompatible types when assigning to type Participant from type struct Participant

标签: c

解决方案


推荐阅读