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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#include<stdio.h>
#include<string.h>
#include<malloc.h>
struct element
{
char mot[27];
struct element *next;
};
typedef struct element element;
typedef struct element *list;
list hama;
char chaine[1000],MOT[27],caractere; int indice=0; int code,cpt=1,i=0;
// ajoud en que d'un element dans la liste hama
list ajout_queu()
{
element* e=(element*)malloc(sizeof(element));
// si la variable MOT est pas vide, INSERER dans le champ
strcpy(e->mot,MOT);
e->next=NULL;
if(hama==NULL)
{
hama=e;
}
else
{
element *t=hama;
while(t->next != NULL)
t=t->next;
t->next=e;
}
}
// fonction qui permet de compter le nombre de mot d'une liste chaine.
int nb()
{
element* t=hama; int i=0;
while(t != NULL)
{
t=t->next;
i++;
}
return(i-1);
}
// lire le contenue des fichier de la liste hama
void printf()
{
FILE *F; char chaine[100]; int i=0;
element* t=hama;
while(t!=NULL)
{
printf("%s",t->mot);
F=fopen(t->mot,"r");
if(F==NULL)
{
printf("\n fichier incorrecte ");
printf("\n");
printf("\n");
}
else
{
printf("\n");
printf("chaine lue dans le fichier %s est :",t->mot);
printf("\n");
printf("\n");
while(! feof(F))
putchar(fgetc(F));
fclose(F);
printf("\n");
printf("\n");
}
t=t->next;
printf("\n");
}
printf("\n %d mots ",nb());
}
// procedure qui met les mots du fichier dans la list hama
void lecture_mot(char*chemin)
{
FILE*F; char car,care; int indicateur=0;
F=fopen(chemin,"r");
if(F==NULL)
{
printf("\n fichier incorrecte ");
printf("\n");
printf("\n");
}
else
{
printf("les mots du fichier %s sont:\n",chemin);
printf("\n");
printf("\n");
while(! feof(F))
{
caractere=fgetc(F);
while(caractere=='/')
{
car=fgetc(F);
if(car=='/')
{
while(caractere!='\n')
caractere=fgetc(F);
caractere=fgetc(F);
}
}
while(caractere=='<')
{
while(caractere!='>')
caractere=fgetc(F);
caractere=fgetc(F);
}
caractere=caractere;
// Si le caractere courant est un separateur de mot,ajouter \0 dans MOT
if(caractere==' ' or caractere=='*' or caractere=='?' or caractere=='.'or caractere=='\n' or caractere==':' or caractere==';' or caractere==',' or caractere=='[' or caractere==']' or caractere=='(' or caractere==')' or caractere=='!')
{
// si le caractere courant est un separateur de mot.
if(indicateur==0)
{
MOT[indice]='\0';
ajout_queu();
indice=0;
indicateur=1;
}
}
else
// Sinon affecter le caractere courant dans MOT et incrementer l'indice de MOT.
{
MOT[indice]=caractere;
indice++;
indicateur=0;
}
}
}
}
main()
{
char fichier[21]; char car,h=' ';
FILE*F1;
printf("donner le nom du fichier a parcourire :");
scanf("%20s",fichier);
lecture_mot(fichier);
printf();
scanf("%c",&h);
scanf("%c",&h);
} |