(file-handler)+implemented write_to_file
First line is the data width, then the sand particles of each cell per row.
This commit is contained in:
@@ -61,4 +61,19 @@ bool load_from_file(state_t *state, const char *filepath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool write_to_file(state_t *state, const char *filepath)
|
bool write_to_file(state_t *state, const char *filepath)
|
||||||
{}
|
{
|
||||||
|
FILE *fp = fopen(filepath, "w");
|
||||||
|
fprintf(fp, "%lu\n", state->dwidth);
|
||||||
|
for (size_t i = 0; i < state->dwidth; ++i)
|
||||||
|
{
|
||||||
|
for (size_t j = 0; j < state->dwidth; ++j)
|
||||||
|
{
|
||||||
|
fprintf(fp, "%d", state->data[(i * state->dwidth) + j]);
|
||||||
|
if (j != state->dwidth - 1)
|
||||||
|
fprintf(fp, ",");
|
||||||
|
}
|
||||||
|
fprintf(fp, "\n");
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user