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
| int j=0,x=0;
char * mot; /*pointeur sur le tableau contenant un mot */
mot = malloc (2*sizeof(char)); /* creation du tableau dynamique pour le mot */
if( mot == NULL )
{
fprintf(stderr,"Allocation impossible");
exit(EXIT_FAILURE);
}
/* parcours de la ligne */
for (j=0 ; j<=Tailleligne ; j++) {
if(isspace(ligne[j]) || ispunct(ligne[j])) { /*si espace OU ponctuation */
if(nbAjout==0) {
MaChaine = inserer_debut(mot, Numligne); /*Si premier ajout on sauvegarde le mot en tete */
nbAjout=100;
}
else{ MaChaine=inserer_fin(MaChaine, mot, Numligne); } /* Sinon on sauvegarde le mot en queue */
free(mot); /* on detruit le mot */
mot = malloc (2*sizeof(char)); /* creation de mot */
if( mot == NULL )
{
fprintf(stderr,"Allocation impossible");
exit(EXIT_FAILURE);
}
x=0; /* et c'est reparti pour un nouveau mot !! */
}
else {
mot[x]=ligne[j]; /* recuperation du caractère */
mot = realloc (mot, x+1 *(2*sizeof(char))); /* Ajout d'un element au tableau */
printf(" mot[%d] = %c \n", x , mot[x] );
x++; /* et on reboucle */
}
} |
Partager