#include <stdio.h>
#include <stdlib.h>
struct Grid {
int _id;
// other properties...
};
struct GridReadStream {
FILE *file;
};
struct GridReadStream newGridReadStream(const char filename) {
struct GridReadStream stream = (struct GridReadStream )malloc(sizeof(struct GridReadStream));
stream->file = fopen(filename, "r");
return stream;
}
int readGrid(struct GridReadStream stream, struct Grid grid) {
if (fread(grid, sizeof(struct Grid), 1, stream->file) == 1) {
return 1;
} else {
return 0;
}
}
int main() {
const char *filename = "grid_data.bin";
struct GridReadStream *stream = newGridReadStream(filename);
if (stream == NULL) {
perror("Error opening file");
return 1;
}
struct Grid grid;
while (readGrid(stream, &grid)) {
// Process grid data...
printf("Grid ID: %d\n", grid._id);
}
fclose(stream->file);
free(stream);
return 0;
}