|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
BANQUE
Information sur la source
Description
Gérer un tableau, trier, afficher, opération sur les chaînes de caracteres
Source
- // kReAtoR
-
- #include <conio.h>
- #include <stdio.h>
- #include <alloc.h>
- #include <string.h>
- #define taille 10
-
- typedef struct{
- char *nom;
- int ref;
- int nbr;
- }article;
-
- void main()
-
- {
- int nbr_art=0;
- int i,j=0,rep,test;
- char *elmnt_suppr, *elmnt_modif;
- article t[taille],t2[taille],mem;
- char rep_2;
-
- for(i=0;i<taille;i++)
- {
- t[i].nom=(char*)malloc(sizeof(char*));
- t2[i].nom=(char*)malloc(sizeof(char*));
- }
- elmnt_suppr=(char*)malloc(sizeof(char*));
- elmnt_modif=(char*)malloc(sizeof(char*));
- mem.nom=(char*)malloc(sizeof(char*));
-
- MENU:
- textcolor(LIGHTGREEN);
- textbackground(BLACK);
- clrscr();
- cprintf("\n\r +------------------------------------------------------------+\n\r");
- cprintf(" | 1 -> Afficher l'etat des element du magasin |\n\r");
- cprintf(" | 2 -> Supprimer un element dans le magasin |\n\r");
- cprintf(" | 3 -> Ajouter un elements dans le magasin |\n\r");
- cprintf(" | 4 -> Modifier le contenu d'un element |\n\r");
- cprintf(" | 5 -> Rechercher le nombre d'element inferieur a 5 |\n\r");
- cprintf(" | 6 -> Informations sur un element particulier |\n\r");
- cprintf(" +-+--------------------------------------------------------+-+\n\r");
- cprintf(" | 0 -> Quitte le programme |\n\r");
- cprintf(" +--------------------------------------------------------+\n\n\r\r");
-
- cprintf("Votre choix ? ");
- scanf(" %d",&rep);
- if(rep==1){goto LBL_1;}
- if(rep==2){goto LBL_2;}
- if(rep==3){goto LBL_3;}
- if(rep==4){goto LBL_4;}
- if(rep==5){goto LBL_5;}
- if(rep==6){goto LBL_6;}
- if(rep==0){goto END;}
-
-
-
- LBL_1:
- if(nbr_art==0)
- {
- textcolor(WHITE);
- clrscr();
- gotoxy(20,10);
- cprintf("+---------------------------------+\n\r");
- gotoxy(20,11);
- cprintf("| Vous n'avez rien en stock |\n\r");
- gotoxy(20,12);
- cprintf("+---------------------------------+\n\r");
- getch();
- goto MENU;
- }
- clrscr();
- cprintf(" Nom: | Reference: | Stock(s):\n\r");
- cprintf("----------------------+-----------------------+----------\n\r");
- for(i=0;i<nbr_art;i++)
- {
- gotoxy(2,i+3);
- printf(" %s",t[i].nom);
- gotoxy(25,i+3);
- printf(" %d",t[i].ref);
- gotoxy(49,i+3);
- printf(" %d",t[i].nbr);
- getch();
- }
- getch();
- goto MENU;
-
-
-
-
-
- LBL_2:
- clrscr();
- if(nbr_art==0)
- {
- goto LBL_1;
- }
- cprintf("Entrer le nom de l'element a supprimer: \n\r");
- scanf(" %s",elmnt_suppr);
- for(i=0;i<=nbr_art;i++)
- {
- test=strcmp(t[i].nom,elmnt_suppr);
- if(i>=nbr_art)
- {goto LBL_1;}
- if(test==0)
- {
- for(j=i;j<=nbr_art;j++)
- {
- t[j]=t[j+1];
- }
- t[nbr_art-1]=t[nbr_art];
- nbr_art--;
- cprintf("Element supprime avec succes.\n\r");
- }
- }
- cprintf("Appuyez sur une touche pour revenir au menu.\n\r");
- getch();
- goto MENU;
-
-
-
- LBL_3:
- clrscr();
- do
- {
- cprintf("Nom de l'element: ");
- scanf(" %s",t[nbr_art].nom);
- for(i=0;i<=nbr_art;i++)
- {
- for(i=0;i<=nbr_art;i++)
- {
- test=strcmp(t[j].nom,t[i].nom);
- if(i!=j && test==0)
- {
- cprintf("\n\rCet element est deja present.\n\r");
- textcolor(YELLOW);cprintf("i");
- textcolor(GREEN);cprintf("ncrementer ou ");
- textcolor(YELLOW);cprintf("c");
- textcolor(GREEN);cprintf("reer un nouvel article ? ");
- scanf(" %c",&rep_2);
- if(rep_2=='c'){textcolor(LIGHTGREEN);goto LBL_3;}
- if(rep_2=='i')
- {
- t[i].nbr++;
- }
- }
- }
- }
- if(rep_2!='i')
- {
- cprintf("Reference: ");
- scanf(" %d",&t[nbr_art].ref);
- cprintf("Nombre d'element de ce type: ");
- scanf(" %d",&t[nbr_art].nbr);
- nbr_art++;
- for(i=0;i<nbr_art;i++)
- {
- for(j=i;j<nbr_art;j++)
- {
- test=strcmp(t[j].nom,t[i].nom);
- if(test<0)
- {
- mem=t[i];
- t[i]=t[j];
- t[j]=mem;
- i--;
- }
- }
- }
- }
- cprintf("\n\rEncore un article ? ");
- scanf(" %c",&rep_2);
- cprintf("\n\r\n\r");
- }while(nbr_art<taille && rep_2=='o');
- getch();
- goto MENU;
-
-
-
- LBL_4:
- textcolor(WHITE);
- clrscr();
- if(nbr_art==0)
- {
- goto LBL_1;
- }
- cprintf("Entrer le nom de l'element a modifier:\n\r");
- scanf(" %s",elmnt_modif);
- for(i=0;i<nbr_art;i++)
- {
- test=strcmp(t[i].nom,elmnt_modif);
- if(i>nbr_art && test!=0)
- {
- cprintf("Votre elemnet n'a pas ete trouve.\n\r");
- }
- if(test==0)
- {cprintf("Nombre en stock: %d , entrer la nouvelle quantite: ",t[i].nbr);
- scanf(" %d",&t[i].nbr);
- }
- }
- cprintf("\n\rAppuyer sur une touche pour revenir au menu.\n\r");
- getch();
- goto MENU;
-
-
-
- LBL_5:
- clrscr();
- if(nbr_art==0)
- {
- goto LBL_1;
- }
- textcolor(YELLOW);
- cprintf("Liste des elements dont le stock est inferieur a 5:\n\r");
- cprintf("---------------------------------------------------\n\r");
- for(i=0;i<nbr_art;i++)
- {
- if(t[i].nbr<5)
- {
- t2[i]=t[i];
- textcolor(WHITE);
- cprintf("Nom: %-20s Reference: %-10d Stock: %-15d \n\r",t2[i].nom,t2[i].ref,t2[i].nbr);
- getch();
- }
- }
- getch();
- goto MENU;
-
-
-
- LBL_6:
- textcolor(WHITE);
- clrscr();
- if(nbr_art==0)
- {
- goto LBL_1;
- }
- cprintf("Entrer le nom de l'element:\n\r");
- scanf(" %s",elmnt_modif);
- for(i=0;i<nbr_art;i++)
- {
- test=strcmp(t[i].nom,elmnt_modif);
- if(test==0)
- {
- cprintf("\n\r+--------------------------------------------\n\r");
- cprintf("|Nom: %-30s\n\r",t[i].nom);
- cprintf("|Reference: %-30d\n\r",t[i].ref);
- cprintf("|Stock: %-30d\n\r",t[i].nbr);
- cprintf("+--------------------------------------------\n\r");
- }
- }
- if(test!=0)
- {cprintf("Element non present.");}
-
- cprintf("\n\r\n\rAppuyer sur une touche pour revenir au menu.\n\r");
- getch();
- goto MENU;
-
-
- END:
- textcolor(YELLOW);
- printf("\n");
- cprintf("Le programme a ete interrompu. Appuyez sur une touche pour le quitter.");
- getch();
- }
-
-
-
-
// kReAtoR
#include <conio.h>
#include <stdio.h>
#include <alloc.h>
#include <string.h>
#define taille 10
typedef struct{
char *nom;
int ref;
int nbr;
}article;
void main()
{
int nbr_art=0;
int i,j=0,rep,test;
char *elmnt_suppr, *elmnt_modif;
article t[taille],t2[taille],mem;
char rep_2;
for(i=0;i<taille;i++)
{
t[i].nom=(char*)malloc(sizeof(char*));
t2[i].nom=(char*)malloc(sizeof(char*));
}
elmnt_suppr=(char*)malloc(sizeof(char*));
elmnt_modif=(char*)malloc(sizeof(char*));
mem.nom=(char*)malloc(sizeof(char*));
MENU:
textcolor(LIGHTGREEN);
textbackground(BLACK);
clrscr();
cprintf("\n\r +------------------------------------------------------------+\n\r");
cprintf(" | 1 -> Afficher l'etat des element du magasin |\n\r");
cprintf(" | 2 -> Supprimer un element dans le magasin |\n\r");
cprintf(" | 3 -> Ajouter un elements dans le magasin |\n\r");
cprintf(" | 4 -> Modifier le contenu d'un element |\n\r");
cprintf(" | 5 -> Rechercher le nombre d'element inferieur a 5 |\n\r");
cprintf(" | 6 -> Informations sur un element particulier |\n\r");
cprintf(" +-+--------------------------------------------------------+-+\n\r");
cprintf(" | 0 -> Quitte le programme |\n\r");
cprintf(" +--------------------------------------------------------+\n\n\r\r");
cprintf("Votre choix ? ");
scanf(" %d",&rep);
if(rep==1){goto LBL_1;}
if(rep==2){goto LBL_2;}
if(rep==3){goto LBL_3;}
if(rep==4){goto LBL_4;}
if(rep==5){goto LBL_5;}
if(rep==6){goto LBL_6;}
if(rep==0){goto END;}
LBL_1:
if(nbr_art==0)
{
textcolor(WHITE);
clrscr();
gotoxy(20,10);
cprintf("+---------------------------------+\n\r");
gotoxy(20,11);
cprintf("| Vous n'avez rien en stock |\n\r");
gotoxy(20,12);
cprintf("+---------------------------------+\n\r");
getch();
goto MENU;
}
clrscr();
cprintf(" Nom: | Reference: | Stock(s):\n\r");
cprintf("----------------------+-----------------------+----------\n\r");
for(i=0;i<nbr_art;i++)
{
gotoxy(2,i+3);
printf(" %s",t[i].nom);
gotoxy(25,i+3);
printf(" %d",t[i].ref);
gotoxy(49,i+3);
printf(" %d",t[i].nbr);
getch();
}
getch();
goto MENU;
LBL_2:
clrscr();
if(nbr_art==0)
{
goto LBL_1;
}
cprintf("Entrer le nom de l'element a supprimer: \n\r");
scanf(" %s",elmnt_suppr);
for(i=0;i<=nbr_art;i++)
{
test=strcmp(t[i].nom,elmnt_suppr);
if(i>=nbr_art)
{goto LBL_1;}
if(test==0)
{
for(j=i;j<=nbr_art;j++)
{
t[j]=t[j+1];
}
t[nbr_art-1]=t[nbr_art];
nbr_art--;
cprintf("Element supprime avec succes.\n\r");
}
}
cprintf("Appuyez sur une touche pour revenir au menu.\n\r");
getch();
goto MENU;
LBL_3:
clrscr();
do
{
cprintf("Nom de l'element: ");
scanf(" %s",t[nbr_art].nom);
for(i=0;i<=nbr_art;i++)
{
for(i=0;i<=nbr_art;i++)
{
test=strcmp(t[j].nom,t[i].nom);
if(i!=j && test==0)
{
cprintf("\n\rCet element est deja present.\n\r");
textcolor(YELLOW);cprintf("i");
textcolor(GREEN);cprintf("ncrementer ou ");
textcolor(YELLOW);cprintf("c");
textcolor(GREEN);cprintf("reer un nouvel article ? ");
scanf(" %c",&rep_2);
if(rep_2=='c'){textcolor(LIGHTGREEN);goto LBL_3;}
if(rep_2=='i')
{
t[i].nbr++;
}
}
}
}
if(rep_2!='i')
{
cprintf("Reference: ");
scanf(" %d",&t[nbr_art].ref);
cprintf("Nombre d'element de ce type: ");
scanf(" %d",&t[nbr_art].nbr);
nbr_art++;
for(i=0;i<nbr_art;i++)
{
for(j=i;j<nbr_art;j++)
{
test=strcmp(t[j].nom,t[i].nom);
if(test<0)
{
mem=t[i];
t[i]=t[j];
t[j]=mem;
i--;
}
}
}
}
cprintf("\n\rEncore un article ? ");
scanf(" %c",&rep_2);
cprintf("\n\r\n\r");
}while(nbr_art<taille && rep_2=='o');
getch();
goto MENU;
LBL_4:
textcolor(WHITE);
clrscr();
if(nbr_art==0)
{
goto LBL_1;
}
cprintf("Entrer le nom de l'element a modifier:\n\r");
scanf(" %s",elmnt_modif);
for(i=0;i<nbr_art;i++)
{
test=strcmp(t[i].nom,elmnt_modif);
if(i>nbr_art && test!=0)
{
cprintf("Votre elemnet n'a pas ete trouve.\n\r");
}
if(test==0)
{cprintf("Nombre en stock: %d , entrer la nouvelle quantite: ",t[i].nbr);
scanf(" %d",&t[i].nbr);
}
}
cprintf("\n\rAppuyer sur une touche pour revenir au menu.\n\r");
getch();
goto MENU;
LBL_5:
clrscr();
if(nbr_art==0)
{
goto LBL_1;
}
textcolor(YELLOW);
cprintf("Liste des elements dont le stock est inferieur a 5:\n\r");
cprintf("---------------------------------------------------\n\r");
for(i=0;i<nbr_art;i++)
{
if(t[i].nbr<5)
{
t2[i]=t[i];
textcolor(WHITE);
cprintf("Nom: %-20s Reference: %-10d Stock: %-15d \n\r",t2[i].nom,t2[i].ref,t2[i].nbr);
getch();
}
}
getch();
goto MENU;
LBL_6:
textcolor(WHITE);
clrscr();
if(nbr_art==0)
{
goto LBL_1;
}
cprintf("Entrer le nom de l'element:\n\r");
scanf(" %s",elmnt_modif);
for(i=0;i<nbr_art;i++)
{
test=strcmp(t[i].nom,elmnt_modif);
if(test==0)
{
cprintf("\n\r+--------------------------------------------\n\r");
cprintf("|Nom: %-30s\n\r",t[i].nom);
cprintf("|Reference: %-30d\n\r",t[i].ref);
cprintf("|Stock: %-30d\n\r",t[i].nbr);
cprintf("+--------------------------------------------\n\r");
}
}
if(test!=0)
{cprintf("Element non present.");}
cprintf("\n\r\n\rAppuyer sur une touche pour revenir au menu.\n\r");
getch();
goto MENU;
END:
textcolor(YELLOW);
printf("\n");
cprintf("Le programme a ete interrompu. Appuyez sur une touche pour le quitter.");
getch();
}
Conclusion
Tres simplifié, que des "LABEL" !!! A la barbare !!!!
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Comparez les prix Nouvelle version
|