diff options
Diffstat (limited to 'šola/p2/dn/naloga.c')
-rw-r--r-- | šola/p2/dn/naloga.c | 30 |
1 files changed, 30 insertions, 0 deletions
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++; + } +} |