RECHERCHER :
COMMUNAUTE MP
Identifiez vous ...
Devenir Membre
J'ai oublié mon MDP
DOMAINE MP
Bavardages
Langages Généraux
Langages Web
Langages DotNet
Autres langages
Dev. Jeux Video
Sécurité
Sys. Exploitation
Graphismes
Logiciels
Réseaux
Bases de données
Méthodologies
Emplois High-tech
Aide juridique
Articles juridiques
FORUM
Index des forums
Ajouter un sujet
Rechercher sujet
Contact Responsable
Devenir modérateur
CHAT MP IRC
Votre pseudo ...
Srv: irc.moteurprog.com
Chan: #MoteurProg
PARTICIPER
Plus de 3500 emplois.
Rechercher un job
Déposez votre CV
Emplois High-tech

Visiteur MP

 ca parait difficile

Forum : C
Sous Catégorie : Aucune
Type du sujet : Sujet Normale
FAQ : FAQ C

SUIVI DES SUJETS PAR MAIL

SUIVI PAR MAIL INACTIF

RESOLUTION DU SUJET SUJET NON RESOLU
BLOQUAGE DU SUJET SUJET ACTIF
APPARTENANCE A LA FAQ N'APPARTIENT PAS A LA FAQ


POSTER UN NOUVEAU SUJET REPONDRE A CE SUJET

FORUM C

PREMIERE PAGE

PAGE PRECEDENTE

Page précedente

Page suivante

PAGE SUIVANTE

DERNIERE PAGE
gersen
Nouveau membre
Inscrit : 29/02/2008
Messages : 4
Message
#152650
Posté le 01/05/08 à 21:11
Bonjour, a vous j'ai besoin d'aide svp
j'ai un pt'it probleme avec un un exercice en c
cet exercice consiste a chercher d'abord un chemins entre 2 stations a et b ensuite chercher tous les chemins entre ces deux meme stations.
on a notre reseau d'arc qui est dans un fichiers d'arc qui contient notre reseau d'arc


on a typedef struct {char nom[20];
int numero_station ;}station;

typedef struct{station station_depart;
station station_arrive;
int indicateur;/*indicateur sert a eviter les boucles */
}arc;


mon probleme est que je trouve le fonctions chemins mais a chaque fois que je trouve un arc appartenant a mon chemin je copie l'arc dasn un tableau et je mets l'indicateur a 1 pour eviter de boucler sur le meme chemins ,le probleme qui se pose c lors de l'utilisation de tous les chemins la fonctions trouve les chemins evident mais les chemins intermediaire elle ne les trouves pas car je mets une condition que si indicateur==1 je passe a la lecture de l'arc suivant ,cam'aide et ca me penalise en meme temps


exemple:
le chemins entre A et B est:
AC,CR,RT,TO,OB
dans la fct tous les chemins il va prendre tous les chemins a part
AC,CR,RP,PB
AC,CG,GP,PB
...etc


#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<string.h> /*fonction creer station*/ typedef struct station station; struct station { char nom[20]; int num; }; /*le type arc*/ typedef struct arc arc; struct arc { station stat_depart; station stat_arriv; int indic; }; /*fonction de creation de station*/ station creer_station(char *nom,int num) {station nouv; { nouv.num=num; strcpy(nouv.nom,nom); } } /*fonctions de comparaison entre 2 stations*/ int meme_station(station a,station b) { if (strcmp(a.nom,b.nom)==0&&a.num==b.num) return(1); else return(0); } /*fonctions de creation d'un arc*/ arc creer_ar(station a,station b,int indicateur) {arc nouv; {nouv.stat_depart=a; nouv.stat_arriv=b; nouv.indic=indicateur; } return(nouv); } /* appartenance*/ int appartient(station a,arc c) { if ((strcmp(c.stat_depart.nom,a.nom)==0)&&(c.stat_depart.num==a.num)) return(1); else if ((strcmp(c.stat_arriv.nom,a.nom)==0)&&(c.stat_arriv.num==a.num)) return(1); else return(0); } /*comparaisons de 2 arc*/ int memearc(arc c1,arc c2) { if((appartient(c1.stat_depart,c2)==1)&&(appartient(c1.stat_arriv,c2)==1)) return(1); else return(0); } /*fonctions se suivent*/ int sesuivent(arc c1,arc c2) { if ((memearc(c1,c2)==0)&&(strcmp(c1.stat_arriv.nom,c2.stat_depart.nom)!=0)) return(1); else return(0); } /* PARTIE 3*/ FILE *creerReseau(int nbr) {int i=1;arc a;FILE* fich; fich=fopen("tp2.dat","w"); if(fich==NULL) {printf("erreur d'ouverture");exit(-1);} while(i<=nbr) { printf("donner le nom de votre station de depart de l'arc Numero %d\n",i); scanf("%s",&a.stat_depart.nom); printf("donner le nom de votre station d'arrive de l'arc Numero %d\n",i); scanf("%s",&a.stat_arriv.nom); fwrite(&a,sizeof(arc),1,fich); i++; } fclose(fich); return(fich); } /*rechercher un arc*/ int rechercheArc(station depart,station arrive,FILE *p) {arc a; p=fopen("tp2.dat","r"); if(p==NULL) {printf("erreur d'ouverture");exit(-1);} while(!feof(p)) {fread(&a,sizeof(arc),1,p); if((appartient(depart,a)==1)&&(appartient(arrive,a)==1)) return(1); } return(0); } /*copier 2 arc*/ arc copier(arc a) {arc b; strcpy(b.stat_depart.nom,a.stat_depart.nom); b.stat_depart.num=a.stat_depart.num; b.stat_arriv.num=a.stat_arriv.num; strcpy(b.stat_arriv.nom,b.stat_arriv.nom); } /*suppression d'un ARC*/ /* rechercher l'existance d'un chemin*/ arc *recherche(station a ,station b,FILE *p) {arc c,save,tab[50];int trouv=0,fin,i=0; p=fopen("tp2.dat","r"); while((trouv==0)&&(!feof(p))) {fread(&c,sizeof(arc),1,p); if((appartient(a,c)==1)&&(strcmp(a.nom,c.stat_depart.nom)==0)) {trouv=1; save=c; trouv=1; rewind(p); } } if(trouv==0){return(0);} while((!feof(p))&&(appartient(b,c)==0)) {fread(&c,sizeof(arc),1,p); if((memearc(c,save)==0)&&(sesuivent(save,c)==1)) {save=c; rewind(p); tab[i]=save; i++; } } fclose(p); return(tab); } main() {int nbr,i;FILE *fichier;arc*s,d;station depart,arrive; printf("DONNEZ LE NOMBRE D'ARC DU RESEAU \n"); scanf("%d",&nbr); fichier=creerReseau(nbr); printf("QUELLE SONT LES STATIONS QUE VOUS VOULEZ CHERCHER LE CHEMINS ENTRE ELLES\n"); printf("STATION DE DEPART:"); scanf("%s",&depart.nom); printf("STATION D'ARRIVE:"); scanf("%s",&arrive.nom); fclose(fichier); s=recherche(depart,arrive,fichier); i=0; while(i<nbr) {printf("%s %s \n",s[i].stat_depart.nom,s[i].stat_arriv.nom); i++; } getch(); }

__________________________
fight club

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 


    PAGE : [1]



.: Site Web développé par Julien Pichot et l'équipe MPWG avec www.evolvia-web.com :.