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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <conio.h>
/*la structure d'un article (lecture à partir de article.txt)*/
struct article
{
int code_art;
int code_four;
char design[20];
char famille;
float prix;
};
typedef struct article ARTICLE;
/*la structure décrivant les composants d'un produit,
(lecture à partir de process.txt) */
struct process
{
int code_composant;
int code_compose;
int qte;
};
typedef struct process PROCESS;
/*liste chainée des articles :*/
struct list_article
{
ARTICLE art;
struct list_article *suiv;
};
typedef struct list_article LIST_ARTICLE;
/*arbre du contenu de process.txt :*/
struct arbre
{
ARTICLE art;
int qte;
struct arbre *fils,*frere;
};
typedef struct arbre ARBRE;
/***********************************************************/
/*get_last(list_chain)/
-renvoi le dernier maillon de list_chain
-concerne la liste chainée des articles */
LIST_ARTICLE* get_last(LIST_ARTICLE* list)
{
LIST_ARTICLE*pcour;
pcour=list;
if(list==NULL) exit(1);
else
while(pcour->suiv !=NULL)
pcour=pcour->suiv;
return (pcour);
}
/***********************************************************/
//fonction inserer_queue; insère un nouveau maillon à la queue de liste
LIST_ARTICLE* inserer_queue(ARTICLE kart,LIST_ARTICLE *lart)
{
LIST_ARTICLE *l,*p;
l=(LIST_ARTICLE*)malloc(sizeof(LIST_ARTICLE));
l->art=kart;
l->suiv=NULL;
if(lart==NULL)
{
lart=l;
}
else
{
p=get_last(lart);
p->suiv=l;
}
return(lart);
}
/***********************************************************/
/*fonction aff_list_art
-affiche la liste chainée des articles */
void aff_list_art(LIST_ARTICLE*list)
{
LIST_ARTICLE*move;
move=list;
if (list==NULL) printf("liste vide");
else
while(move!=NULL)
{
printf("%4d %4d %20s %c %10.3f\n",move->art.code_art,move->art.code_four,move->art.design,move->art.famille,move->art.prix);
move=move->suiv;
}
}
/***********************************************************/
void main()
{
FILE *f;
char s[100];
ARTICLE a;
LIST_ARTICLE *lart=NULL;
f=fopen("c:\\article.txt","r");
rewind(f);//placer curseur au debut du fichier
while(fgets(s,100,f))
{
sscanf(s,"%4d %4d %20s %c %f",&a.code_art,&a.code_four,a.design,&a.famille,&a.prix);
lart=inserer_queue(a,lart);
/*affichage de la liste des articles: */
aff_list_art(lart);
}
fclose(f);
} |
Partager