Bonjour a tous, j aimerais avoir un peu d aide voila g un petit programme et je dois le trier, mais je c pas comment faire
#include <stdlib.h> #include <stdio.h> struct commande { char nom[80]; char article[80]; int nombre,prix; struct commande *suiv; };
void print_com(struct commande com) { printf ("%s%s%d%d",com.nom,com.article,com.nombre,com.prix); }
struct commande *max_com( struct commande * l_com) { struct commande *pmax; struct commande *pcour; int vmax,vcour; if ( l_com == NULL) return (NULL); else { pmax = l_com; vmax = (pmax -> nombre) * (pmax -> prix); for (pcour = l_com -> suiv; pcour != NULL;pcour = pcour -> suiv) { vcour = (pcour -> nombre * pcour ->prix); if (vcour>vmax) { vmax = vcour; pmax = pcour; } } return (pmax); } } /*main*/ int main() { FILE * fi; struct commande *l_com = NULL; struct commande *prec, *cour; int val_ret; if ((fi = fopen("commande.data","r"))==NULL) printf ("impossible d ouvrir le fichier commande.data\n"); else { do { cour = malloc(sizeof(struct commande)); val_ret = fscanf(fi,"%s%s%d%d",cour -> nom,cour -> article, &(cour -> nombre), &(cour -> prix)); if(val_ret == EOF) { free(cour); if(l_com != NULL) prec -> suiv = NULL; } else { if (l_com == NULL) l_com = cour; else prec -> suiv = cour; prec = cour; } } while(val_ret != EOF); if (l_com == NULL) printf ("la liste de commande est vide\n"); else { for (cour = l_com; cour !=NULL; cour = cour -> suiv) print_com(*cour); printf ("la commande maximun est : \n"); print_com ( *max_com(l_com)); } fclose(fi); } }
|