blob: 69c68e5f780ec4fdba92589994cb9df0b3ec46eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;}
|