fixed some bugs on resp. Added global_resp and added error handling for char

Signed-off-by: Mathéo Hersan <matheohersan@MacBook-Pro-de-Matheo.local>
pull/2/head^2
Mathéo Hersan 2 years ago
parent 4e17746abb
commit 91542d8c75
No known key found for this signature in database
GPG Key ID: 4EF19C64D78EC91B

BIN
app

Binary file not shown.

@ -1,5 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include "responsable.h"
#include "../interface/interface_resp.h"
int chargementArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tPhysique)
{
@ -27,22 +29,19 @@ int chargementArticles(int tRef[], float tPoids[], float tVol[], float tPrix[],
return i;
}
void sauvegadArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], float tLogique)
{
void sauvegardArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique){
int i;
FILE * fe;
fe = fopen("articles.txt","w");
if ( fe == NULL )
fe = fopen("donnee/articles.txt", "w");
if ( fe == NULL)
{
perror("fopen");
return -1;
return;
}
for ( i = 0; i < tLogique; ++i)
for ( i = 0; i < tLogique; i++)
{
fwritef(fe,"%d\t %.2f\t %.2f\t %.2f\n", );
fprintf(fe,"%d %f %f %f\n", tRef[i], tPoids[i], tVol[i], tPrix[i]);
}
fclose(fe);
}

@ -1,5 +1,5 @@
#include<stdio.h>
int chargementArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tPhysique);
void sauvegadArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique);
void sauvegardArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique);
int ajouterArticle( int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique, int tPhysique, int ref, float poids, float volume, float prix);

@ -1,12 +1,3 @@
#include <stdio.h>
#include "responsable.h"
#include "../interface/interface_resp.h"
int main (void)
{
int tPhysique = 10, tRef[10], tLogique = 0;
float tPoids[10], tVol[10], tPrix[10];
tLogique = chargementArticles( tRef, tPoids, tVol, tPrix, tPhysique);
affichArticles( tRef, tPoids, tVol, tPrix, tLogique);
return 0;
}

@ -20,30 +20,25 @@ void affiche_client(int a){
/*
* Sert à lancer le menu et faire choisir l'utilisateur
*/
void menu(int *choix, int jour) {
void menu_client(int *choix, int jour) {
affiche_client(jour);
printf("Vous choisissez: ");
scanf("%d", choix);
while (*choix < 0)
{
while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 5) {
while (getchar() != '\n'); // Nettoie le tampon d'entrée en cas de saisie invalide
affiche_client(jour);
printf("Vous choisissez: ");
printf("Veuillez entrer un choix valide ! \n");
scanf("%d", choix);
printf("Veuillez entrer un choix valide : ");
}
}
void global_client(){
void global_client() {
int choix, jour;
menu(&choix, jour);
menu_client(&choix, jour);
switch (choix) {
case 1:
afficherDonneesClient();
break;
default:
printf("Veuillez entrer un choix valide ! \n");
printf("Veuillez entrer un choix valide !\n");
break;
}
}
}

@ -1,5 +1,5 @@
#include<stdio.h>
void affiche_client(int a);
void menu(int *choix, int a);
void menu_client(int *choix, int a);
void global_client();

@ -1,6 +1,22 @@
#include <stdio.h>
#include "interface_resp.h"
void affiche_resp(int a){
printf("\n");
printf("+-------------+ \n");
printf("|| Bonjour ! ||\n") ;
printf("+-------------+ \n");
printf("\n");
printf("+-----------------------------------------------------------------+\n");
printf("|| Que voulez-vous faire ? \t \t \t \t \t || \n");
printf("||\t1 : Afficher les articles \t \t \t \t || \n");
printf("||\t2 : Afficher un article \t \t \t \t || \n");
printf("||\t3 : Afficher un client \t \t \t \t \t || \n");
printf("||\t4 : Afficher les clients \t \t \t \t || \n");
printf("||\t5 : Réinitialiser le panier. \t \t \t \t || \n");
printf("+-----------------------------------------------------------------+\n");
}
void affichArticles( int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique)
{
int i;
@ -72,7 +88,7 @@ void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix)
while ( poids < 0 )
{
printf("Entrez un nombre correct !");
scanf("%d", poids);
scanf("%f", poids);
}
}
printf("Entrez le volume du nouveaux produit");
@ -82,7 +98,7 @@ void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix)
while ( poids < 0 )
{
printf("Entrez un nombre correct !");
scanf("%d", poids);
scanf("%f", poids);
}
}
printf("Entrez le prix du nouveaux produit");
@ -92,7 +108,33 @@ void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix)
while ( prix < 0 )
{
printf("Entrez un nombre correct !");
scanf("%d", prix);
scanf("%f", prix);
}
}
}
}
void menu_resp(int *choix, int jour) {
affiche_resp(jour);
printf("Vous choisissez: ");
while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 5) {
while (getchar() != '\n'); // Nettoie le tampon d'entrée en cas de saisie invalide
affiche_resp(jour);
printf("Veuillez entrer un choix valide : ");
}
}
void global_resp(){
int choix, a, tRef[100], tLogique = 0;
float tPoids[100], tVol[100], tPrix[100];
menu_resp(&choix, a);
switch (choix) {
case 1:
affichArticles(tRef, tPoids, tVol, tPrix, tLogique);
break;
default:
printf("Veuillez entrer un choix valide ! \n");
break;
}
}

@ -2,4 +2,6 @@ void affichArticles( int tRef[], float tPoids[], float tVol[], float tPrix[], in
void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique, int val);
void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogique, int val);
void affichUnClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique, int val);
void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix);
void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix);
void menu_resp(int *choix, int jour);
void global_resp();

@ -15,7 +15,7 @@ int choixInterface(void) {
fprintf(stderr,"Veuillez entrer un choix valide ! \n");
}
switch (choix) {
case 1: printf("Vous avez choisit l'interface responsable.\n"); break;
case 1: printf("Vous avez choisit l'interface responsable.\n");
case 2: printf("Vous avez choisit l'interface client.\n");
}
return choix;
@ -23,7 +23,7 @@ int choixInterface(void) {
int main(){
switch (choixInterface()) {
//case 1: global_resp();
case 1: global_resp();
case 2: global_client();
}
return 0;

Loading…
Cancel
Save