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
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TAILLE_MAX 1000
typedef char tab[TAILLE_MAX][TAILLE_MAX];
/***fonction recherche qui permit de rechercher une chaine d'un tableau */
recherche(char chaine,tab tab_ins,int tail_tab)
{ int i=0,n=0,j=0;
for(i=0;i<tail_tab;i++)
{
if (strcmp(tab_ins[i],chaine)==0 )
{
n=0;
exit(n);
}
else if ((strcmp(tab_ins[i],chaine)!=0 )&&(tab_ins!=""))
j++;
}
if (j==tail_tab)
n=-1;
return n;
}
/*** programme principale qui permit de tester l'existence d'un chaine de caractere
de fichier dont un tableau */
main()
{
int i=0,j=0,n=0;
FILE*fichier=NULL;
char chaine[50];// chaine extrait de fichier
tab tab_ins={"kl","hh","hafedhg"};// exemple tab_ins pour tester
int tail_tab=3;
char c;
fichier = fopen("test.txt","r");
while((c=getc(fichier))!=EOF)
{
printf("%c",c);
if ((c!= '\n')&&(c!='\t'))
{
strcat(chaine,c);
}
else
{ if (recherche(chaine,tab_ins,tail_tab)==-1)
printf("erreur variable ' %s ' non déclare linge %d ",chaine,i);
memset (chaine, 0, sizeof (chaine));
// vidage de la chaine
}
}
fclose(fichier);
return 0;
} |
Partager