summaryrefslogtreecommitdiffstats
path: root/inf/rtk/2020-offline/razdeli.c
diff options
context:
space:
mode:
Diffstat (limited to 'inf/rtk/2020-offline/razdeli.c')
-rw-r--r--inf/rtk/2020-offline/razdeli.c65
1 files changed, 65 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <offline.h>
+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;
+}