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
| void choix(char depart[TAILLE_MAX], char arrivee[TAILLE_MAX],int nbsommets, Station metro[nbsommets], int *id_depart, int *id_arrivee,char nom_depart[TAILLE_MAX], char nom_arrivee[TAILLE_MAX] )
{
int ok_dep=0,ok_fin=0, i=0, reponse=2;
printf("Quelle est votre station de d�part : ");
fgets(depart,TAILLE_MAX,stdin);
char *p=strchr(depart,'\n');
if(p!=NULL) *p='\0'; //On enleve le \n pour que lorsque l'on souhaite afficher le nom de la station il ne va pas automatiquement à la ligne après le nom
printf("\nQuelle est votre station d'arrivee : ");
fgets(arrivee,TAILLE_MAX, stdin);
char *q=strchr(arrivee,'\n');
if(q!=NULL) *q='\0';//On enleve le \n pour que lorsque l'on souhaite afficher le nom de la station il ne va pas automatiquement à la ligne après le nom
while(((ok_fin==0) || (ok_dep==0)) && i<nbsommets)
{
if(ok_dep!=1)
{
//printf("%s\n%s\n\n", depart, metro[i].nom_station);
if(strcmp(depart,metro[i].nom_station)==0)
{
*id_depart=metro[i].id_station;
//printf("%s\n%s", depart, metro[i].nom_station);
ok_dep=1;
}
else if(strncmp(metro[i].nom_station,depart,strlen(depart)-1)==0)
{
printf("voulez vous cette station de départ:\n%s oui:1 non:2 \n",metro[i].nom_station);
scanf("%d",&reponse);
if(reponse==1)
{
ok_dep=1;
*id_depart=metro[i].id_station;
strcpy(nom_depart,metro[i].nom_station);
}
}
}
if(ok_fin!=1)
{
if(strcmp(arrivee,metro[i].nom_station)==0 && ok_dep==1)
{
*id_arrivee=metro[i].id_station;
//printf("%s%s", arrivee, metro[i].nom_station);
ok_fin=1;
}
else if(strncmp(metro[i].nom_station,arrivee,strlen(arrivee)-1)==0)
{
printf("voulez vous cette station d'arrivée:\n%s oui:1 non:2 \n",metro[i].nom_station);
scanf("%d",&reponse);
if(reponse==1)
{
ok_fin=1;
*id_arrivee=metro[i].id_station;
strcpy(nom_arrivee,metro[i].nom_station);
}
}
}
i++;
}
if(*id_arrivee==-1 || *id_depart==-1)
{
printf("saisie incorrect\n");
choix(depart,arrivee,nbsommets,metro,id_depart,id_arrivee, nom_depart,nom_arrivee);
}
} |
Partager