From 1ffa25152f18588b381fa9260f437f07d9a04003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 15 Apr 2024 10:33:24 +0200 Subject: =?UTF-8?q?=C5=A1ola?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "\305\241ola/p2/dn/.gitignore" | 6 ++++++ "\305\241ola/p2/dn/dn06-naloga1.c" | 29 +++++++++++++++++++++++++++ "\305\241ola/p2/dn/dn06-naloga2.c" | 41 ++++++++++++++++++++++++++++++++++++++ "\305\241ola/p2/dn/naloga.c" | 30 ++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 "\305\241ola/p2/dn/.gitignore" create mode 100644 "\305\241ola/p2/dn/dn06-naloga1.c" create mode 100644 "\305\241ola/p2/dn/dn06-naloga2.c" create mode 100644 "\305\241ola/p2/dn/naloga.c" (limited to 'šola/p2') diff --git "a/\305\241ola/p2/dn/.gitignore" "b/\305\241ola/p2/dn/.gitignore" new file mode 100644 index 0000000..099718c --- /dev/null +++ "b/\305\241ola/p2/dn/.gitignore" @@ -0,0 +1,6 @@ +* +!*.c +!*.txt +!*_testi +!.gitignore +!*_izhodisca/ diff --git "a/\305\241ola/p2/dn/dn06-naloga1.c" "b/\305\241ola/p2/dn/dn06-naloga1.c" new file mode 100644 index 0000000..9301d71 --- /dev/null +++ "b/\305\241ola/p2/dn/dn06-naloga1.c" @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include "naloga1.h" +char * zdruzi (char ** nizi, char * locilo) { + int ll = strlen(locilo); + int len = 1-ll; + char ** n = nizi; + while (*n) + len += strlen(*n++)+ll; + char * r = malloc(sizeof *r * (len+1)); + char * rorig = r; + while (*nizi) { + strcpy(r, *nizi); + r += strlen(*nizi); + nizi++; + if (*nizi) { + strcpy(r, locilo); + r += ll; + } + } + return rorig; +} +#ifndef test +int main () { + return 0; +} +#endif diff --git "a/\305\241ola/p2/dn/dn06-naloga2.c" "b/\305\241ola/p2/dn/dn06-naloga2.c" new file mode 100644 index 0000000..021930c --- /dev/null +++ "b/\305\241ola/p2/dn/dn06-naloga2.c" @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#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 diff --git "a/\305\241ola/p2/dn/naloga.c" "b/\305\241ola/p2/dn/naloga.c" new file mode 100644 index 0000000..70e5cd6 --- /dev/null +++ "b/\305\241ola/p2/dn/naloga.c" @@ -0,0 +1,30 @@ +int steviloZnakov (char * niz, char znak) { + int r = 0; + while (*niz) { + if (*niz++ == znak) + r++; + return r; +} +#include +char * kopirajDoZnaka (char * niz, char znak) { + strchr(niz, znak)[0] = '\0'; + char * r = strdup(niz); + niz[strlen(niz)][0] = znak; + return r; +} +char ** razcleni (char * besedilo, char locilo, int * stOdsekov) { + char * p = besedilo; + char ** r = NULL; + *stOdsekov = 0; + while (1) { + if (*p == locilo || !*p) { + *p = '\0'; + r = realloc(r, ++*stOdsekov*sizeof *r); + r[*stOdsekov-1] = strdup(besedilo); + besedilo = p+1; + if (!*p) + return r; + } + p++; + } +} -- cgit v1.2.3