c pas l'armée du salut ici non plus !!!
moi j'te conseille flex, c ce quil y a de plus rapide et efficace (et ca se compile en C). voila en gros le contenu (je suis plus trop sur de la synthaxe exacte):
{% #define MAX_MOTS 2048; char buffer [255]; int idChar; int nbLigne; int nbMot; char **mots;
void caractere(char car) { buffer[idChar] = car; idChar++; }
void finmot() { buffer[idChar] = '\0', int taille = strlen(buffer); char *str = (char*)malloc(taille*sizeof(char)); strcpy(str, buffer); idChar = 0; mots[nbMot] = str; nbMot++; }
void newline() { if (idChar > 0) { finmot(); } nbLigne++; }
%}
blanc [\t ] nl [\n]
%%
blanc {finmot();} nl {newline();} . {caractere(yytext[0]);}
%%
int main(int argc, char **argv) { idChar = 0; nbLigne = 0; nbMot = 0; mots = (char**) malloc(MAX_MOTS * sizeof(char*)); yyin = fopen("monfichier.txt", "r"); yyparse(); printf("%d mots, %d lignes, dernier mot ajoute : %s\n", nbMot, nbLigne, mots[nbMot-1]); return 0; }
|