summaryrefslogtreecommitdiffstats
path: root/šola/p2/dn/dn06-naloga2.c
diff options
context:
space:
mode:
Diffstat (limited to 'šola/p2/dn/dn06-naloga2.c')
-rw-r--r--šola/p2/dn/dn06-naloga2.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/šola/p2/dn/dn06-naloga2.c b/šola/p2/dn/dn06-naloga2.c
new file mode 100644
index 0000000..021930c
--- /dev/null
+++ b/šola/p2/dn/dn06-naloga2.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include "naloga2.h"
+int ** ap2pp (int (*kazalec)[N], int izvornoStVrstic, int ciljnoStVrstic) {
+ int * ka = (int *) kazalec;
+ int ** r = malloc(ciljnoStVrstic*sizeof *r);
+ int outstolpcev = izvornoStVrstic*N/ciljnoStVrstic;
+ for (int i = 0; i < izvornoStVrstic*N; i++) {
+ int j = i/outstolpcev;
+ int k = i%outstolpcev;
+ if (!k) {
+ r[j] = malloc((outstolpcev+1)*sizeof *(r[j]));
+ r[j][outstolpcev] = 0;
+ }
+ r[j][k] = ka[i];
+ }
+ return r;
+}
+int (*pp2ap(int ** kazalec, int izvornoStVrstic, int * ciljnoStVrstic))[N] {
+ int * r = NULL;
+ int rlen = 0;
+ for (int i = 0; i < izvornoStVrstic; i++)
+ for (int j = 0; kazalec[i][j]; j++) {
+ r = realloc(r, ++rlen*sizeof *r);
+ r[rlen-1] = kazalec[i][j];
+ }
+ if (rlen % N != 0) {
+ r = realloc(r, (rlen/N+1)*N * sizeof *r);
+ while (rlen % N)
+ r[rlen++] = 0;
+ }
+ *ciljnoStVrstic = rlen/N;
+ return (int (*)[N]) r;
+}
+#ifndef test
+int main () {
+ return 0;
+}
+#endif