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
SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE !MISHRA READER : UN LECTEUR RSS TRèS ZUNE STYLE EN OPEN SOURCE ! par Vko
Hier durant une session dédiée aux Techdays 2012, j'ai eu le plaisir d'annoncer la sortie de la Béta 2 de Mishra Reader. C'est quoi ? Pour les utilisateurs, c'est une vraie expérience de lecture de flux RSS sur Windows. Rien à voir avec les produit...
Cliquez pour lire la suite de l'article par Vko
Forum
ALGORITHMESALGORITHMES par whayoub
Cliquez pour lire la suite par whayoub
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|