summaryrefslogtreecommitdiff
path: root/sem_3/SYSTEME/TP2/ex9
diff options
context:
space:
mode:
Diffstat (limited to 'sem_3/SYSTEME/TP2/ex9')
-rw-r--r--sem_3/SYSTEME/TP2/ex9/strsplitbin0 -> 8715 bytes
-rw-r--r--sem_3/SYSTEME/TP2/ex9/strsplit.c54
2 files changed, 54 insertions, 0 deletions
diff --git a/sem_3/SYSTEME/TP2/ex9/strsplit b/sem_3/SYSTEME/TP2/ex9/strsplit
new file mode 100644
index 0000000..65fe687
--- /dev/null
+++ b/sem_3/SYSTEME/TP2/ex9/strsplit
Binary files differ
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;}