summaryrefslogtreecommitdiffstats
path: root/šola/p2/dn/dn06-naloga2.c
blob: 021930c96bcb3b9289ca99ec6d40544a52185a90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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