diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-08-25 19:19:50 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-08-25 19:19:50 +0100 |
commit | 58970e8a68583e61e93091989af335cdac218085 (patch) | |
tree | 38f4373a7193c27e918afafadd5630bf5943e78b /file-handler.c | |
parent | f155f0e0884b18a9fdac3a302bb9c9fa1dd7e5aa (diff) | |
download | abelian-sandpile-58970e8a68583e61e93091989af335cdac218085.tar.gz abelian-sandpile-58970e8a68583e61e93091989af335cdac218085.tar.bz2 abelian-sandpile-58970e8a68583e61e93091989af335cdac218085.zip |
(file-handler)+implemented write_to_file
First line is the data width, then the sand particles of each cell per
row.
Diffstat (limited to 'file-handler.c')
-rw-r--r-- | file-handler.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/file-handler.c b/file-handler.c index 765eec5..0f9e838 100644 --- a/file-handler.c +++ b/file-handler.c @@ -61,4 +61,19 @@ bool load_from_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; +} |