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
| #include <stdio.h>
#include <conio.h>
#include <stdlib.h>
struct p{
int ref;
char nom[30];
float p_vente,p_achat;
struct p* next;
};
typedef struct p * produit;
produit ajouter_enfin(produit list);
void afficher_tout(produit list);
main()
{
produit la_liste,la_liste_ret;
la_liste_ret=ajouter_enfin(la_liste);
afficher_tout(la_liste_ret);
}
//Fonction Ajouter_enqueue
produit ajouter_enfin(produit list){
/* allocation du noeud */
produit p_new = (produit)malloc (sizeof (produit));
/* si tout s'est bien passe : */
if (p_new != NULL)
{
/* mise a jour des champs : */
/* donnees */
printf("donner le ref de produit");
scanf("%d",&p_new->ref);
printf("donner le nom du produit");
scanf("%s",&p_new->nom);
printf("donner la prix d'achat ");
scanf("%f",&p_new->p_achat);
printf("donner la prix de vente");
scanf("%f",&p_new->p_vente);
/* chainage par defaut */
p_new->next = NULL;
/* chainage */
if (list == NULL)
{
/* c'est le premier : */
list = p_new;
}
else
{
/* on cherche le dernier noeud */
produit p = list;
while (p->next != NULL)
{
/* pointer sur le suivant */
p = p->next;
}
/* modification du chainage */
p->next = p_new;
}
}
return list;
}
//Procédure affichage
void afficher_tout(produit list){
if(list==NULL){
printf("aucune liste a afficher ajoutez une\n");
}
else
{
printf("la ref de produit est:%d\n",list->ref);
printf("le nom de produit est:%s\n",list->nom);
printf("le prix d'achat de produit est:%f\n",list->p_achat);
printf("le prix de vente de produit est:%f\n",list->p_vente);
}
} |
Partager