diff options
| author | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:05:53 +0200 |
|---|---|---|
| committer | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:05:53 +0200 |
| commit | 9fe033ea88c2f705ec18c232873d056e0c229d72 (patch) | |
| tree | 0647dc8c51610c7336c88c04de2068ea14b21e17 /sem_3/SYSTEME/TP2/ex9/strsplit.c | |
Initial commit
Diffstat (limited to 'sem_3/SYSTEME/TP2/ex9/strsplit.c')
| -rw-r--r-- | sem_3/SYSTEME/TP2/ex9/strsplit.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sem_3/SYSTEME/TP2/ex9/strsplit.c b/sem_3/SYSTEME/TP2/ex9/strsplit.c new file mode 100644 index 0000000..69c68e5 --- /dev/null +++ b/sem_3/SYSTEME/TP2/ex9/strsplit.c @@ -0,0 +1,54 @@ +#include<stdlib.h> +#include<stdio.h> + +//char ** strsplit ( char*,char); +char ** strsplit ( char * fichier, char sep ) { + printf("entree dans strsplit"); + int nbsep = 0; + int cpt = 0; + while ( fichier[cpt] != '\0' ) { + nbsep += (fichier[cpt] == sep ? 1 : 0); + cpt ++; + } + printf("%d bloc differents",cpt); + int i = 0, offset = 0, offsetchar = 0; + char ** tab = malloc((cpt + 1)*sizeof(char*)) ; + printf("tab init"); + //tab[cpt] = NULL; + printf("%p", tab[cpt+1]); + for ( i =0; i < cpt+1; i ++ ) { + tab[i] = malloc ( 100 * sizeof(char)); + } + i =0; + cpt = 0; + while ( fichier[i] != '\0' ) { + if (fichier[i] != sep) { + tab[offset][offsetchar] = fichier[i]; + offsetchar ++; + cpt ++; + } + else { + tab[offset][offsetchar]='/0'; + tab[offset] = realloc ( tab[offset], (cpt) * sizeof(char)); + offset++; + offsetchar = 0; + cpt = 0 ; + } + } +return tab; +} + + +int main (int argc, char ** argv) { +int i=0,cpt=0; +printf("jusqu'ici tout va bien"); +char ** tableau = strsplit(argv[1], argv[2][0]); +while (tableau[i]!=NULL) { + while (tableau[i][cpt]!='\0') { + printf("%c",tableau[i][cpt]); + cpt ++; + } + printf("\n"); +i ++; +} +return 0;} |
