From 2057a987a330e086659a9bf95fa69cf168f861a3 Mon Sep 17 00:00:00 2001 From: sijanec Date: Fri, 15 Jan 2021 08:22:07 +0100 Subject: =?UTF-8?q?joj=20=C5=A1ol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inf/rtk/2020-offline/razdeli.c | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 inf/rtk/2020-offline/razdeli.c (limited to 'inf/rtk/2020-offline/razdeli.c') diff --git a/inf/rtk/2020-offline/razdeli.c b/inf/rtk/2020-offline/razdeli.c new file mode 100644 index 0000000..24c36c1 --- /dev/null +++ b/inf/rtk/2020-offline/razdeli.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include +int main (int argc, char ** argv) { + char ** n = malloc(sizeof(char *) * 1); + size_t * v = malloc(sizeof(size_t) * 1); + size_t nalog = 0; + int returnstatus = 0; + char c = getchar(); + int vrs = 0; + size_t pjev; + char fn[69]; + FILE * fd; + /* struct rtk_kos * p; */ + n[0] = NULL; + v[0] = 0; + while (!feof(stdin)) { + n[nalog] = realloc(n[nalog], sizeof(char)*v[nalog]+2); + n[nalog][v[nalog]++] = c; + n[nalog][v[nalog]] = '\0'; + if (c == RTK_EOL) { + if (vrs == 0 && strncmp("Stiskanje", n[0], strlen("Stiskanje") != 0)) { + fprintf(stderr, "vhodna datoteka se ne začne s \"Stiskanje\"\n"); + returnstatus = 1; + goto returncleanly; + } + if ((vrs - 2) % 3 == 2) { /* če je bila to naloga */ + n[nalog][--v[nalog]] = '\0'; + fprintf(stderr, "prepisal nalogo %lu\r", nalog); + nalog++; + n = realloc(n, sizeof(char*)*(nalog+1)); + n[nalog] = NULL; + v = realloc(v, sizeof(size_t)*(nalog+1)); + } + v[nalog] = 0; /* gremo na začetek prostora za nalogo */ + vrs++; + } + c = getchar(); + } + fprintf(stderr, "zapisal naloge v spomin. \n"); + for (vrs = 0; vrs < nalog; vrs++) { + fprintf(stderr, "shranjujem nalogo %d\n", vrs); + snprintf(fn, 69, "naloga%d.txt", vrs+1); + fd = fopen(fn, "w"); + pjev = 0; + while (n[vrs][pjev] != '\0') + putc(n[vrs][pjev++], fd); + fprintf(stderr, "zadnji znak je %02x\n", n[vrs][--pjev]); + fclose(fd); + /* pjev = rtk_resi(n[vrs], p); + free(p); */ + } + returncleanly: + while (nalog > 0) { + nalog--; + free(n[nalog]); + n[nalog] = NULL; + } + free(n); + n = NULL; + free(v); + v = NULL; + return returnstatus; +} -- cgit v1.2.3