Accueil > > > BANQUE
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
|
Derniers Blogs
COMMENT MAPPER UNE VUE SQL SUR UNE COLLECTION DE COMPLEX TYPE?COMMENT MAPPER UNE VUE SQL SUR UNE COLLECTION DE COMPLEX TYPE? par Matthieu MEZIL
Avec EF, les vues doivent être mappées sur des entity types. Le problème c'est que les entity types doivent avoir une clé. Avec EF, nous avons les complex type qui n'ont pas de clé mais les vues ne peuvent pas être mappées dessus. Avec EF4, il est possibl...
Cliquez pour lire la suite de l'article par Matthieu MEZIL [WF4] UN BINDING ACTIVITY/ACTIVITYDESIGNER QUI PASSE MAL?[WF4] UN BINDING ACTIVITY/ACTIVITYDESIGNER QUI PASSE MAL? par JeremyJeanson
Certain d'entre vous on peut être vécu cette situation embarrassante après quelques temps passer avec WF4 : Au début avec mon " ActivityDesigner" , tout allait bien. Et puis un jour j'ai au des problèmes de " Binding" . Alors nous sommes allé sur le site ...
Cliquez pour lire la suite de l'article par JeremyJeanson MYTIC - SHAREPOINT 2010 : DéJà UN MYTHE MICROSOFT ?MYTIC - SHAREPOINT 2010 : DéJà UN MYTHE MICROSOFT ? par junarnoalg
La prochaine session de MyTIC aura lieu à Namur, le 23 mars prochain. Pendant presque une heure, nous parlerons de SharePoint 2010. Voici un aperçu du programme.
Accueil : 17h30 Début de la session : 18h00 - Les nouvelles int...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
ERREUR DE POINTEURERREUR DE POINTEUR par africanwinners
Cliquez pour lire la suite par africanwinners CLISTCTRLCLISTCTRL par dorras7
Cliquez pour lire la suite par dorras7
Logiciels
Academy System (10.9.4.0)ACADEMY SYSTEM (10.9.4.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods
|