listes chainées
Hors ligneBlack_light Le 24/12/2013 Ă  14:38 Profil de Black_light Configuration de Black_light

bonjour,

svp voici mon code qui crĂ©e des repertoires:un repertoire doit contenire au max deux sous-repertoires et des fichiers l'affichage ne marche pas .je vois pas ou est le probleme : 

typedef struct {int jour;int mois;int annee;}date;

 typedef struct {char nomfich[15];long taille; date datecreation;}infofich; 

 typedef struct elt{infofich info; struct elt *svt;} fichier; 

typedef struct eltr{char nom_rep[15]; char sous_rep1[15]; char sous_rep2[15]; struct elt *lien;}rep; 

typedef struct eltl{rep info; struct eltl *next;} liste;


/*creation d'une liste de fichier */


fichier *creation(int m) 

{ fichier *q,*T=NULL;    int j=0;

for(j=0;j<m;j++)

{ q=(fichier *)malloc(sizeof(fichier));

 printf("entrez le contenue du fichier: nom,taille \n");

scanf("%s %ld",q->info.nomfich,&q->info.taille);

printf("entrez la date de creation du fichier:jj,mm,AAAA\n");

scanf("%d %d %d ",&q->info.datecreation.jour,&q->info.datecreation.mois,&q->info.datecreation.annee);

q->svt=T;    T=q;} 

return(T);}


/*creation d'une liste de repertoire avec double chainage un avec le suivant et l'autre avec la liste de fichier*/


liste *creat_rep(int n)

{ liste *tete=NULL,*p; int i,m;

for (i=0;i<n;i++)

{ p=(liste *)malloc(sizeof(liste)); 

printf("entrez le nom du repertoire et des sous repertoires \n");

scanf("%s %s %s",p->info.nom_rep,p->info.sous_rep1,p->info.sous_rep2);

p->next=tete; tete=p;

printf("entrez le nombre de fichier dans ce repertoire \n"); 

 scanf("%d",&m);

p->info.lien=creation(m); } 

return(tete); }


/*afficher un repertoire donné*/


void affichage(liste *tete,char *ch)

{ liste *p,*r; fichier *q;

for(p=tete;p!=NULL &&(strcmp(p->info.nom_rep,ch)!=0) ;r=p,p=p->next)

if (p==NULL) printf("ce repertoire n'existe pas \n");

printf("%s %s %s", (r->next)->info.nom_rep, (r->next)->info.sous_rep1, (r->next)->info.sous_rep2);

for(q=(r->next)->info.lien;q!=NULL;q=q->svt)

printf("%s %ld la date de creation est: %d %d %d",q->info.nomfich, q->info.taille, q->info.datecreation.jour, q->info.datecreation.mois, q->info.datecreation.annee);

}


int main()

{ liste *tete=NULL,*p; fichier *q,*r; int n; char ch[15];

printf("combien de repertoire voulez-vous crĂ©e ?? \n"); 

 scanf("%d",&n);

tete=creat_rep(n);

printf("entrez le nom du repertoire que vous voulez afficher \n"); 

 scanf("%s",ch);

affichage(tete,ch); 

 return 0;}

--

Hors ligneAnthony Le 24/12/2013 Ă  15:15 Profil de Anthony Configuration de Anthony

Admin

Salut :) Un peu dur de s'y retrouver, mĂȘme en collant ton script dans un outil tel que Pastebin on a du mal Ă  y voir clair. Pourrais-tu indenter ton code, sauter des lignes, que ce soit plus clair ? ça aidera Ă  te rĂ©pondre :)

--

Hors ligneBlack_light Le 24/12/2013 Ă  18:42 Profil de Black_light Configuration de Black_light

c'est fait j'espere que c'est mieux ainsi .merci

--

Vous avez résolu votre problème avec VIC ? Faites-le savoir sur les réseaux sociaux !
Vulgarisation-informatique.com
Cours en informatique & tutoriels