/** * Writing an array of pointers to structures using fwrite * This one works * @author gtowell * Created: April 2021 * **/ #include #include #include #define SIZ 100 typedef struct { int aa; double bb; } aabb; int main(int argc, char const *argv[]) { aabb **arr = malloc(SIZ * sizeof(aabb *)); for (int i = 0; i < SIZ; i++) { arr[i] = malloc(1 * sizeof(aabb)); arr[i]->aa = i; arr[i]->bb = sqrt(i); } FILE *fp = fopen("astrfp", "w"); int d = SIZ; fwrite(&d, sizeof(int), 1, fp); for (int i = 0; i < SIZ; i++) fwrite(arr[i], sizeof(aabb), 1, fp); fclose(fp); return 0; }