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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| #include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
#include<stdlib.h>
#include<dos.h>
typedef struct commande;
struct commande
{
char produit;
char client;
char email;
int qte ;
double prixU ;
struct commande *next;
};
typedef struct commande* List;
char produit[50] = "";
char client[50] = "";
char email[50] = "";
int qte = 0;
double prixU = 0.0;
FILE *fp, *ft;
int i, n, ch, l, found;
List ajouterElement(List list, char produit, char client, char email, int qte, float prixU)
{
List llist = list;
List nouvelElement;
nouvelElement = (List)malloc(sizeof(List));
nouvelElement->produit = produit;
nouvelElement->client = client;
nouvelElement->email = email;
nouvelElement->qte = qte;
nouvelElement->prixU = prixU;
nouvelElement->next = llist;
return nouvelElement;
}
void afficherListe(List list)
{
List tmp = list;
while (tmp != NULL)
{
printf("\n Produit : ");
printf("%s", tmp->produit);
printf("\n Client : ");
printf("%s", tmp->client);
printf("\n Email : ");
printf("%s", tmp->email);
printf("\n Quantite : ");
printf("%d", tmp->qte);
printf("\n Prix Unitaire : ");
printf("%.3lf", tmp->prixU);
tmp = tmp->next;
printf("\n");
}
}
int main()
{
List list = NULL;
char buf[1000];
char buffer[50] = "C:\\Users\\asus\\Desktop\\projectC\\commandes.txt";
char name;
char produit[50];
char client[50];
char email[50];
int qte;
double prixU;
main:
system("cls"); /* ************ Menu *********************** */
printf("\n\t\t==============================================\n\t\t // Gestion des commandes d'une entreprise //\n\t\t==============================================\n\n");
printf("\n =======================\n\t>< MENU ><\n =======================\n\n [1] Ajouter une commande\n [2] Afficher toutes les commandes\n [3] Clients fideles\n [0] Quitter\n\n =======================\n\n");
printf("[+] Choisir une option > ");
scanf("%d", &ch);
switch (ch)
{
case 0:
printf("\n[?] Voulez vous quitter ?");
break;
/* ********************* Ajouter une commande************ */
case 1:
system("cls");
fp = fopen(buffer, "a");
for (;;)
{
fflush(stdin);
printf("\n[!] Pour quitter saisir un Espace puis Entrer\n");
printf("\n =====================================================\n\t\t>< Ajout de commandes ><\n =====================================================\n\n Produit : ");
scanf("%[^\n]", &produit);
if (_stricmp(produit, "") == 0 || _stricmp(produit, " ") == 0)
break;
printf(" Client : ");
scanf("%s", &client);
printf(" Email Client : ");
gets(email);
printf(" Quantite : ");
scanf("%d", &qte);
printf(" Prix Unitaire : ");
scanf("%f", &prixU);
fprintf(fp, "\nProduit\t: %s\nClient\t: %s\nEmail\t: %s\nQuantite\t: %d\nPrix Unitaire\t: %.3lf\n", produit, client, email, qte, prixU);
system("cls");
list = ajouterElement(list, produit, client, email, qte, prixU);
//fwrite(&list, 1, sizeof(list), fp);
}
fclose(fp);
break;
/* ********************* List des commandes ************************* */
case 2:
system("cls");
printf("\n\t\t\t===========================\n\t\t\t // Liste des commandes //\n\t\t\t===========================\n\n");
if ((fp = fopen(buffer, "r")) == NULL)
{
printf("Liste de commandes vide !");
_getch();
goto main;
}
else {printf("\n\t\t\t===========================\n\t\t\t // Liste des commandes //\n\t\t\t===========================\n\n");
afficherListe(list);
}
break;
case 3:
default:
printf("Choix invalid !");
break;
}
printf("\n\n[+] Saisir votre choix:\t\t[1] Menu\t[0] Quitter\n");
printf(">_ ");
scanf("%d", &ch);
switch (ch)
{
case 1:
goto main;
case 0:
break;
default:
printf("Choix invalid !");
break;
}
return 0;
} |
Partager