summaryrefslogblamecommitdiffstats
path: root/šola/p2/dn/dn06-naloga2.c
blob: 021930c96bcb3b9289ca99ec6d40544a52185a90 (plain) (tree)








































                                                                            
#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