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
|
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PAYS "paysphone.bip"
#define TAILLE 1000
int main(void)
{
char ch[]="France";
char chaine[TAILLE];
char cara = 0;
FILE *f_pays;
f_pays = fopen(PAYS,"r");
if(f_pays == NULL)
{
fprintf(stderr,"\n Erreur : Impossible de lire le fichier %s\n",PAYS);
exit(EXIT_FAILURE);
}
else
{
int ind=0;
while(ind !=1)
{
int i=0;
while(i<strlen(chaine))
{
chaine[i]=0;
i++;
}
i=0;
while(!feof(f_pays))
{
cara = fgetc(f_pays);
while(cara != ';')
{
chaine[i]=cara;
cara = fgetc(f_pays);
i++;
}
printf("%s\n",chaine);
if(strcmp(ch,chaine) == 0)
{
printf("%s et %s sont identiques\n",ch,chaine);
ind = 1;
}
while(cara != '\n')
{
cara = fgetc(f_pays);
}
}
}
fclose(f_pays);
}
return(EXIT_SUCCESS);
} |