diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-04-15 10:33:24 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-04-15 10:33:24 +0200 |
commit | 1ffa25152f18588b381fa9260f437f07d9a04003 (patch) | |
tree | 99b688314ca245b80185798e12f1e3450eb2a667 /šola/p2 | |
parent | dn05p2 (diff) | |
download | r-1ffa25152f18588b381fa9260f437f07d9a04003.tar r-1ffa25152f18588b381fa9260f437f07d9a04003.tar.gz r-1ffa25152f18588b381fa9260f437f07d9a04003.tar.bz2 r-1ffa25152f18588b381fa9260f437f07d9a04003.tar.lz r-1ffa25152f18588b381fa9260f437f07d9a04003.tar.xz r-1ffa25152f18588b381fa9260f437f07d9a04003.tar.zst r-1ffa25152f18588b381fa9260f437f07d9a04003.zip |
Diffstat (limited to 'šola/p2')
-rw-r--r-- | šola/p2/dn/.gitignore | 6 | ||||
-rw-r--r-- | šola/p2/dn/dn06-naloga1.c | 29 | ||||
-rw-r--r-- | šola/p2/dn/dn06-naloga2.c | 41 | ||||
-rw-r--r-- | šola/p2/dn/naloga.c | 30 |
4 files changed, 106 insertions, 0 deletions
diff --git a/šola/p2/dn/.gitignore b/šola/p2/dn/.gitignore new file mode 100644 index 0000000..099718c --- /dev/null +++ b/šola/p2/dn/.gitignore @@ -0,0 +1,6 @@ +* +!*.c +!*.txt +!*_testi +!.gitignore +!*_izhodisca/ diff --git a/šola/p2/dn/dn06-naloga1.c b/šola/p2/dn/dn06-naloga1.c new file mode 100644 index 0000000..9301d71 --- /dev/null +++ b/šola/p2/dn/dn06-naloga1.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <string.h> +#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/š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 diff --git a/šola/p2/dn/naloga.c b/šola/p2/dn/naloga.c new file mode 100644 index 0000000..70e5cd6 --- /dev/null +++ b/šola/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 <string.h> +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++; + } +} |