IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

Perdu dans ma liste chaînée


Sujet :

C

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2015
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2015
    Messages : 17
    Points : 14
    Points
    14
    Par défaut Perdu dans ma liste chaînée
    Bonsoir à tous,

    Je me suis un peu perdu dans mon code et je cherche désespérément ce qui tourne pas.
    Il se compile mais ne rempli pas correctement les "options optionnelles"...
    Savez vous ce qui ne va pas..?
    Un grand merci.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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;
    }

  2. #2
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2015
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2015
    Messages : 17
    Points : 14
    Points
    14
    Par défaut
    Bon j'ai quand même reussi à avancer un peu mais il reste des détails qui ne fonctionne pas très bien comme pour le menu, la premiere fois il tourne bien mais des que je veux faire quelque chose d'autre je dois le rentrer 2 fois pour que ca fonctionne...
    Je ne comprend vraiment pas pourquoi..
    Merci beaucoup, il me casse bien la tête ce code..
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
     
    #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
     
    int nb_client;
    /*
     struct ListeRef{
     Client}
     */
     
    // metre a jour liste->fin + adresse
     
    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;
        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;
    };
     
     
     
    enum { OK, KO };
     
     
    void clean(void)
    {
        int c;
        while ((c = getchar ()) != '\n' && c != EOF);
    }
    /*
     initialiasation de la liste
     */
    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 a,int b, int c)  {
        // 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->tabchoix[0] = a;
         nouveau_element->tabchoix[1] = b;
         nouveau_element->tabchoix[2] = c;
     
        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=0;
        int tabchoix[3];
        int idx=0;
     
        printf("Nom ?\n");
        scanf("%" _LG_NOM_STR _REGEXP_NOM , nom);
        clean();
     
        printf("Prenom ?\n");
        scanf("%" _LG_PRENOM_STR _REGEXP_PRENOM , prenom);
        clean();
     
        printf("Adresse ?\n");
        scanf("%" _LG_ADRESSE_STR _REGEXP_ADRESSE , adresse);
        clean();
     
        printf("Telephone ?\n");
        scanf("%" _LG_TELEPHONE_STR _REGEXP_TELEPHONE , telephone);
        clean();
     
        printf("Adresse Mail ?\n");
        scanf("%" _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 !\n");
            }
        }while ((choix_cure!=1)&&(choix_cure!=2)&&(choix_cure!=3));
        int i=0;
        int j=0;
     
        do {
            printf("Soins specifiques optionnels\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");
            scanf("%d", &choix_option);
     
     
            tabchoix[i]=choix_option;
            if( i>=0 && (tabchoix[i]==tabchoix[i-1] || tabchoix[i]==tabchoix[i-2]) ){
     
                printf("voulez vous vraiment selectionnez deux fois la meme option ?\n 1 : OUI\n 2 : NON");
                scanf("%d",&j);
     
                if(j==2){ 
                    i--;
                } 
            }
     
            i++;
     
     
        }
        while (i<3);
        Element * nouveau_element = CreerElement(numero, nom, prenom, telephone, mail, choix_cure, tabchoix[0],tabchoix[1],tabchoix[2]);
     
        if ( nouveau_element == NULL ){
            perror("malloc");
            return 1;
        }
     
        nouveau_element->suivant = liste->debut;
        liste->debut = nouveau_element;
        liste->taille++;
     
     
     
        /*
         printf("Quelle est votre date d'arrivee ? format aaaammjj\n");
         scanf("%d" _LG_DATE_STR _REGEXP_DATE , pclient[*nb_client].date1);
         clean();
         
         printf("Quelle est votre date de depart ? format aaaammjj\n");
         scanf("%d" _LG_DATE_STR _REGEXP_DATE , pclient[*nb_client].date2);
         clean();
         
         if (pclient.date1 >= 20160115 && pclient.date1 <= 20160204)
         {
         printf("Saison Hivernale\n");
         }
         else if ((pclient.date1 >= 20160205 && pclient.date1 <= 20160218) || (pclient.date1 >= 20160326 && pclient.date1 <= 20160708) ||
         (pclient.date1 >= 20160924 && pclient.date1 <=20161007 ))
         {
         printf("Moyenne Saison\n");
         }
         else if ((pclient.date1 >= 20160219 && pclient.date1 <= 20160325) || (pclient.date1 >= 20161008 && pclient.date1 <= 20161202))
         {
         printf("Basse Saison\n");
         }
         else if ((pclient.date1 >= 20160709 && pclient.date1 <= 20160923)
         {
         printf("Haute Saison\n");
         }
         else
         {
         printf("Ressaisissez vos dates\n");
         }
         
         
         
         do{
         printf("Soins specifiques optionnels\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");
         printf("8 : Chocolat");
         printf("9 : Choix d'options termines");
         scanf("%d", &choix);
         pclient.tabchoix[idx++]=choix;
         
         }while (choix!=9)
         (*nb_client)++;
         }
         */
    }
     
    void documentation_client (struct Client * pclient)
    {
        /*
         struct tarif
         {
         int mer;
         int jardin;
         int rue;
         
         struct tarif tarif.hiv.chambresimple;
         tarif.hiv.chambresimple.mer = 200;
         tarif.hiv.chambresimple.jardin = 190;
         tarif.hiv.chambresimple.rue = 175;
         
         struct tarif tarif.hiv.chambrestanddouble;
         tarif.hiv.chambrestanddouble.mer = 150;
         tarif.hiv.chambrestanddouble.jardin = 140;
         tarif.hiv.chambrestanddouble.rue = 125;
         
         struct tarif tarif.hiv.chambresconfsimple;
         tarif tarif.hiv.chambresconfsimple.mer = 230;
         tarif tarif.hiv.chambresconfsimple.jardin = 220;
         tarif tarif.hiv.chambresconfsimple.rue = 200;
         
         struct tarif tarif.hiv.chambresconfdouble;
         tarif tarif.hiv.chambresconfdouble.mer = 175;
         tarif tarif.hiv.chambresconfdouble.jardin = 165;
         tarif tarif.hiv.chambresconfdouble.rue = 150;
         
         struct tarif tarif.hiv.suite;
         tarif tarif.hiv.chambressuite.mer = 400;
         tarif tarif.hiv.chambressuite.jardin = 375;
         
         
         struct tarif tarif.basse.chambresimple;
         tarif.basse.chambresimple.mer = 220;
         tarif.basse.chambresimple.jardin = 200;
         tarif.basse.chambresimple.rue = 190;
         
         struct tarif tarif.basse.chambrestanddouble;
         tarif.basse.chambrestanddouble.mer = 170;
         tarif.basse.chambrestanddouble.jardin = 150;
         tarif.basse.chambrestanddouble.rue = 140;
         
         struct tarif tarif.basse.chambresconfsimple;
         tarif tarif.basse.chambresconfsimple.mer = 250;
         tarif tarif.basse.chambresconfsimple.jardin = 230;
         tarif tarif.basse.chambresconfsimple.rue = 220;
         
         struct tarif tarif.basse.chambresconfdouble;
         tarif tarif.basse.chambresconfdouble.mer = 195;
         tarif tarif.basse.chambresconfdouble.jardin = 175;
         tarif tarif.basse.chambresconfdouble.rue = 165;
         
         struct tarif tarif.basse.suite;
         tarif tarif.basse.chambressuite.mer = 425;
         tarif tarif.basse.chambressuite.jardin = 400;
         
         
         
         struct tarif tarif.moyenne.chambresimple;
         tarif.moyenne.chambresimple.mer = 250;
         tarif.moyenne.chambresimple.jardin = 230;
         tarif.moyenne.chambresimple.rue = 220;
         
         struct tarif tarif.moyenne.chambrestanddouble;
         tarif.moyenne.chambrestanddouble.mer = 200;
         tarif.moyenne.chambrestanddouble.jardin = 180;
         tarif.moyenne.chambrestanddouble.rue = 170;
         
         struct tarif tarif.moyenne.chambresconfsimple;
         tarif tarif.moyenne.chambresconfsimple.mer = 280;
         tarif tarif.moyenne.chambresconfsimple.jardin = 255;
         tarif tarif.moyenne.chambresconfsimple.rue = 245;
         
         struct tarif tarif.moyenne.chambresconfdouble;
         tarif tarif.moyenne.chambresconfdouble.mer =  225 ;
         tarif tarif.moyenne.chambresconfdouble.jardin = 205;
         tarif tarif.moyenne.chambresconfdouble.rue =  195;
         
         struct tarif tarif.moyenne.suite;
         tarif tarif.moyenne.chambressuite.mer = 455;
         tarif tarif.moyenne.chambressuite.jardin = 450;
         
         
         
         struct tarif tarif.haute.chambresimple;
         tarif.haute.chambresimple.mer = 270;
         tarif.haute.chambresimple.jardin = 240;
         tarif.haute.chambresimple.rue = 230;
         
         struct tarif tarif.haute.chambrestanddouble;
         tarif.haute.chambrestanddouble.mer = 230;
         tarif.haute.chambrestanddouble.jardin = 190;
         tarif.haute.chambrestanddouble.rue = 175;
         
         struct tarif tarif.haute.chambresconfsimple;
         tarif tarif.haute.chambresconfsimple.mer = 300;
         tarif tarif.haute.chambresconfsimple.jardin = 265;
         tarif tarif.haute.chambresconfsimple.rue = 250;
         
         struct tarif tarif.haute.chambresconfdouble;
         tarif tarif.haute.chambresconfdouble.mer =  250 ;
         tarif tarif.haute.chambresconfdouble.jardin = 175;
         tarif tarif.haute.chambresconfdouble.rue =  200;
         
         struct tarif tarif.haute.suite;
         tarif tarif.haute.chambressuite.mer = 525;
         tarif tarif.haute.chambressuite.jardin = 455;
         
         };
         
         struct tarif2
         {
         int bienetre;
         int antitabac;
         int minceur;
         
         struct tarif2.hiv;
         tarif2.hiv.bienetre = 440;
         tarif2.hiv.antitabac = 460
         tarif2.hiv.minceur = 560;
         
         struct tarif2.basse;
         tarif2.basse.bienetre = 480;
         tarif2.basse.antitabac = 500
         tarif2.basse.minceur = 600;
         
         struct tarif2.moyenne;
         tarif2.moyenne.bienetre = 520;
         tarif2.moyenne.antitabac = 540;
         tarif2.moyenne.minceur = 650;
         
         struct tarif2.haute;
         tarif2.haute.bienetre = 570;
         tarif2.haute.antitabac = 590;
         tarif2.haute.minceur = 720;
         
         };
         
         struct tarif3
         {
         int traitementpeau;
         int relaxation;
         int sublimage;
         int sante;
         int jambeslourdes;
         int hydratation;
         int ligne;
         int chocolat;
         
         struct tarif3.hiv;
         tarif3.hiv.traitementpeau = 30;
         tarif3.hiv.relaxation = 35;
         tarif3.hiv.sublimage = 40;
         tarif3.hiv.sante = 30;
         tarif3.hiv.jambeslourdes = 35;
         tarif3.hiv.hydratation = 40;
         tarif3.hiv.ligne = 30;
         tarif3.hiv.chocolat = 35;
         
         struct tarif3.basse;
         tarif3.basse.traitementpeau = 33;
         tarif3.basse.relaxation = 38;
         tarif3.basse.sublimage = 43;
         tarif3.basse.sante = 33;
         tarif3.basse.jambeslourdes = 38;
         tarif3.basse.hydratation = 43;
         tarif3.basse.ligne = 33;
         tarif3.basse.chocolat = 38;
         
         struct tarif3.moyenne;
         tarif3.moyenne.traitementpeau = 35;
         tarif3.moyenne.relaxation = 40;
         tarif3.moyenne.sublimage = 45;
         tarif3.moyenne.sante = 35;
         tarif3.moyenne.jambeslourdes = 40;
         tarif3.moyenne.hydratation = 45;
         tarif3.moyenne.ligne = 35;
         tarif3.moyenne.chocolat = 40;
         
         struct tarif3.haute;
         tarif3.haute.traitementpeau = 40;
         tarif3.haute.relaxation = 45;
         tarif3.haute.sublimage = 50;
         tarif3.haute.sante = 40;
         tarif3.haute.jambeslourdes = 45;
         tarif3.haute.hydratation = 50;
         tarif3.haute.ligne = 40;
         tarif3.haute.chocolat = 45;
         
         };
         */
    }
     
    /* 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\nprenom : %s\ntel : %s\nemail : %s\nchoix_cure : %d\n\nchoix option 1 : %d\nchoix option 2 : %d\nchoix option 3 : %d\n\n", idx++, courant->numero, courant->nom, courant->prenom, courant->telephone, courant->mail, courant->choix_cure,courant->tabchoix[0],courant->tabchoix[1],courant->tabchoix[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(void)
    {
        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;
    }

  3. #3
    Expert confirmé
    Inscrit en
    Mars 2005
    Messages
    1 431
    Détails du profil
    Informations forums :
    Inscription : Mars 2005
    Messages : 1 431
    Points : 4 182
    Points
    4 182
    Par défaut
    Tu postes 500 lignes de code brutes au sein desquelles se cache la ou les causes du dysfonctionnement de ton programme, au sujet duquel nous n'avons que des bribes d'information. Ne le prends pas mal mais personne ne va s'amuser à faire une telle revue de code gratuitement. Pose une question précise à propos du comportement détaillé d'un morceau de code de taille raisonnable et nous te viendrons en aide avec plaisir.

  4. #4
    Membre éprouvé Avatar de fenkys
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2007
    Messages
    376
    Détails du profil
    Informations personnelles :
    Âge : 56
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Octobre 2007
    Messages : 376
    Points : 1 054
    Points
    1 054
    Par défaut
    Code C : Sélectionner tout - Visualiser dans une fenêtre à part
    int ajouter_client(Liste * liste)

    Cette fonction fait beaucoup trop de chose. Tu devrais séparer la saisie des données du client avec l'insertion dans la liste. Des fonctions courtes (qui tiennent en totalité dans un écran) et ne faisant qu'une seule chose sont une des clefs du succès.

Discussions similaires

  1. [Free Pascal] Insertion d'éléments dans une liste chaînée
    Par Pacorabanix dans le forum Free Pascal
    Réponses: 4
    Dernier message: 20/04/2010, 00h42
  2. enlever une variable dans une liste chaînée
    Par bisdi dans le forum Débuter
    Réponses: 7
    Dernier message: 24/08/2008, 19h36
  3. Réponses: 6
    Dernier message: 29/04/2007, 18h59
  4. Réponses: 7
    Dernier message: 22/10/2005, 19h20
  5. Insertion d'un noeud dans une liste chaînée
    Par habib106 dans le forum Assembleur
    Réponses: 8
    Dernier message: 07/04/2004, 22h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo