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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
|
//
// main.c
// SUPrimer 2
//
// Created by Simon Leblanc on 3/10/16.
// Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//
#include <stdio.h>
#define _LG_NOM ( 80 + 1 )
#define _LG_NOM_STR "80"
#define _LG_PRENOM ( 80 + 1 )
#define _LG_PRENOM_STR "80"
#define _LG_ADRESSE ( 80 + 1 )
#define _LG_ADRESSE_STR "80"
#define _LG_TELEPHONE ( 13 + 1 )
#define _LG_TELEPHONE_STR "13"
#define _LG_MAIL ( 80 + 1 )
#define _LG_MAIL_STR "80"
#define _LG_DATE ( 10 + 1 )
#define _LG_DATE_STR "10"
#define _LG_CHOIX ( 0 + 1 )
#define _REGEXP_NOM "[ a-zA-Z]"
#define _REGEXP_PRENOM "[ a-zA-Z]"
#define _REGEXP_ADRESSE "[ a-zA-Z-0-9]"
#define _REGEXP_TELEPHONE "[0-9]"
#define _REGEXP_MAIL "[a-zA-Z-0-9@]"
#define _REGEXP_DATE "[0-9]"
#define OUI 1
#define NON 0
static void clean(void)
{
int c;
while ((c = getchar ()) != '\n' && c != EOF){}
}
enum { OK, KO };
enum {TRUE, FALSE};
typedef struct Client Element;
struct Client {
int numero;
char nom [_LG_NOM];
char prenom [_LG_PRENOM];
char adresse[_LG_ADRESSE];
char telephone [_LG_TELEPHONE];
char mail [_LG_MAIL];
int choix_cure;
int choix_option[2];
char date1 [_LG_DATE];
char date2 [_LG_DATE];
int choix1 [_LG_CHOIX];
int tabchoix[8];
struct Client *suivant;
};
typedef struct ListeClient Liste;
struct ListeClient
{
Element *debut;
Element *fin;
int taille;
};
void initialisation (Liste * liste)
{
liste->debut = NULL;
liste->fin = NULL;
liste->taille = 0;
}
Element * CreerElement(int numero, char * nom, char * prenom, char * telephone, char * mail, int choix_cure, int u,int p, int l) {
// D�claration et initialisation du nouvel �l�ment
Element * nouveau_element = (Element*) malloc ( 1 * sizeof(Element) );
// si erreur sur l'allocation
if ( nouveau_element == NULL ) {
return NULL;
}
// affectation des valeurs
nouveau_element->numero = numero;
strcpy(nouveau_element->nom, nom);
strcpy(nouveau_element->prenom, prenom);
strcpy(nouveau_element->mail, mail);
strcpy(nouveau_element->telephone, telephone);
nouveau_element->choix_cure = choix_cure;
nouveau_element->choix_option[0]= u;
nouveau_element->choix_option[1]= p;
nouveau_element->choix_option[2]= l;
nouveau_element->suivant = NULL;
return nouveau_element;
}
/*
ajouter client
*/
int ajouter_client(Liste * liste)
{
int numero = 1;
char nom [_LG_NOM];
char prenom [_LG_PRENOM];
char adresse[_LG_ADRESSE];
char telephone [_LG_TELEPHONE];
char mail [_LG_MAIL];
struct Client pclient;
int choix_cure = 0;
int choix_option[2];
int idx=0;
printf("Nom ?\n");
scanf("%s" _LG_NOM_STR _REGEXP_NOM , nom);
clean();
printf("Prenom ?\n");
scanf("%s" _LG_PRENOM_STR _REGEXP_PRENOM , prenom);
clean();
printf("Adresse ?\n");
scanf("%s" _LG_ADRESSE_STR _REGEXP_ADRESSE , adresse);
clean();
printf("Telephone ?\n");
scanf("%s" _LG_TELEPHONE_STR _REGEXP_TELEPHONE , telephone);
clean();
printf("Adresse Mail ?\n");
scanf("%s" _LG_MAIL_STR _REGEXP_MAIL , mail);
clean();
do {
printf("Cure envisagee?\n1 : Bien etre\n2 : Anti-tabac\n3 : Minceur\n");
while(scanf("%d",&choix_cure) !=1){
int c;
while ((c=getchar()) != '\n' && c != EOF);
printf("Choisi entre 1, 2 ou 3 ducon !\n");
}
}while ((choix_cure!=1)&&(choix_cure!=2)&&(choix_cure!=3));
int i=0;
int j=0;
while(i<3){
printf("Soins specifiques optionnels\n\n");
printf("1 : Traitement de la peau\n");
printf("2 : Relaxation approfondie\n");
printf("3 : Sublim'age\n");
printf("4 : Sante +\n");
printf("5 : Jambes lourdes\n");
printf("6 : Hydratation visage\n");
printf("7 : Ligne\n");
printf("8 : Chocolat\n");
printf("9 : Choix d'options termines\n");
while(scanf("%d", &choix_option[i]) != 1){
int c;
while ((c=getchar()) != '\n' && c != EOF);
printf("Option mal choisi...\n Recommence\n");
};
// A finir
if(choix_option[i]==choix_option[i-1]){
printf("voulez vous vraiment selectionnez deux fois la meme option ?\n 1 : OUI\n 2 : NON");
scanf("%d",&j);
if(j==2){
i--;
}
}
i++;
}
Element * nouveau_element = CreerElement(numero, nom, prenom, telephone, mail, choix_cure, choix_option[0],choix_option[1],choix_option[2]);
if ( nouveau_element == NULL ){
perror("malloc");
return 1;
}
nouveau_element->suivant = liste->debut;
liste->debut = nouveau_element;
liste->taille++;
}
/* affichage de la liste */
void afficher_client (Liste * liste){
Element *courant;
courant = liste->debut;
int idx = 0;
while (courant != NULL){
printf ("[%d] numero : %d\nnom : %s\tprenom : %s\ttel : %s\temail : %s\tchoix de la cure : %d\n choix option 1 : %d\n choix option 2 : \n choix option 3 : \n", idx++, courant->numero, courant->nom, courant->prenom, courant->telephone, courant->mail, courant->choix_cure, courant->choix_option[0],courant->choix_option[1],courant->choix_option[2]);
courant = courant->suivant;
}
}
/* recherche un �tudiant dans la liste */
void rechercher_client (Liste * liste){
char nom [_LG_NOM]; // nom de l'�tudiant
Element *courant;
courant = liste->debut;
int idx = 0;
printf("Saisir nom : ");
scanf("%s" _LG_NOM_STR _REGEXP_NOM , nom);
clean();
while (courant != NULL){
if ( strcmp(nom, courant->nom) == 0 ) {
printf ("[%d] numero : %d\nnom : %s\tprenom : %s\temail : %s\n", idx++, courant->numero, courant->nom, courant->prenom, courant->mail);
}
courant = courant->suivant;
}
}
void menu(int * choix)
{
char reponse [1+1];
printf("******************** Menu ********************\n");
printf("* 1. Entrer un nouveau client *\n");
printf("* 2. Afficher la fiche client *\n");
printf("* 3. Rechercher un client *\n");
printf("* 4. Quitter *\n");
printf("**********************************************\n");
fgets(reponse, sizeof(reponse), stdin);
clean();
*choix = atoi(reponse);
}
int main(int argc, const char * argv[])
{
int choix;
int nb_ami = 0;
// struct Ami ami[MAX_AMIS];
Liste clients;
initialisation(&clients);
do
{
menu(&choix);
switch(choix)
{
case 1 : ajouter_client(&clients); break;
case 2 : afficher_client(&clients); break;
case 3 : rechercher_client(&clients); break;
}
}
while(choix != 4 );
return 0;
} |
Partager