Voici la solution :
#include <stdio.h>
#define TAILLE 32
int main(int argc, char *argv[])
{
FILE * entree;
char ligne[TAILLE];
int cpt = 0;
char *split;
char *nomVille = NULL;
char cChaine[TAILLE];
char cChaineFile[TAILLE];
printf("Donnez le nom du fichier à analyser : ");
fgets(cChaineFile, sizeof cChaineFile, stdin);
/*La chaine contient le retour chariot, il faut donc le supprimer*/
cChaineFile[strlen(cChaineFile)-1] = '\0';
entree = fopen(cChaineFile, "r");
if(entree == NULL){
printf("Le fichier spécifié n'existe pas\n");
return -1;
}
printf("Donnez le nom de la ville à rechercher : ");
fgets(cChaine, sizeof cChaine, stdin);
cChaine[strlen(cChaine)-1] = '\0';
while (fgets(ligne,TAILLE,entree) != NULL){
nomVille = strtok (ligne, "\t");
if( strcasecmp(cChaine, nomVille) == 0){
cpt++;
printf("Ville : %s\t", nomVille);
split = strtok(NULL, "\t");
printf("Latitude : %s\t", split);
split = strtok(NULL, "\t");
printf("Longitude : %s", split);
break;
}
}
if(cpt==0)
printf("La ville %s n'a pas été trouvée\n", cChaine);
system("PAUSE");
return 0;
}
N'hésite pas à poser des questions si tu ne comprends pas qq chose ;-)
-- Alex pour vous servir --