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 :

Projet C gestionnaire étudiants


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2014
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Janvier 2014
    Messages : 1
    Par défaut Projet C gestionnaire étudiants
    Bonjour,

    voici le code de mon projet en C je voudrais faire un gestionnaire d'étudiants où je peux ajouter un étudiant, modifier ou le supprimer même chose pour des matières mais je suis coincé. Ma fonction ajouter marche bien mais quand j'appelle ma fonction modifier le programme retourne au menu principal je ne sais pas pourquoi? voici le Programme

    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
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include<errno.h>
    #define MAX 50
    #define N  50
     
    void Ajouter_etudiant();
    void Ajouter_matiere();
    void Ajouter_evaluation();
    void Supprimer_etudiant();
    void Supprimer_matiere();
    void Supprimer_evaluation();
    void Modifier_etudiant();
    void Modifier_matiere();
    void Modifier_evaluation();
    void  Afficher();
    int LireNombreEntier();
    int Rand();
    int NombreEnregistrementsEtudiant();
    int NombreEnregistrementsMatiere();
    int NombreEnregistrementsEvaluation();
    int RechercheMatiere();
    int RechercheEtudiant();
    void LireChaine(char chaine[], int size);
    void viderBuffer();
    float LireNombreDecimal();
    int Menu_Principal();
    char Menu_etudiant();
    char Menu_matiere();
    char Menu_evaluation();
     
    typedef struct
    {
        long jour,mois,annee;
    } date;
     
     
    typedef struct
        {
            long numero;
            char nom[MAX];
            char prenom[MAX];
            date date_de_naissance;
             char email[MAX];
            char commentaires[MAX];
        }etudiant;
        etudiant un_etudiant;
     
     
    typedef struct
        {
            long code_matiere;
            char libelle[MAX];
            long coefficient;
        }matiere;
        matiere une_matiere;
     
     
    typedef struct
        {
            date date_evaluation;
            long numero_etudiant;
            long code_matiere;
            long note;
        }evaluation;
        evaluation une_evaluation;
     
    int main()
    {
        // Déclation des variables locales:
        int choix=0;
        char choix1,choix2,choix3;
     
        while((choix=Menu_Principal())!= 12 ) {
     
        puts("");
     
    // On propose 3 choix(ajouter supprimer ou modiifier  pour la catégorie étudiant.
     
        switch (choix)
        {
            case 1 :
                {
                   choix1=Menu_etudiant();
     
                     puts("");
                    if (choix1=='a')
                    {
                            Ajouter_etudiant();
                            puts("");
     
                    }
                    if (choix1=='b')
                    {
                            Supprimer_etudiant();
                    }
                     if (choix1=='c')
                    {
                            Modifier_etudiant();
                            puts("");
     
                    }
                    else
                    {
                      puts(" VOUS AVEZ FAIT LE MAUVAIS CHOIX.");
                      puts("");
                      choix1=Menu_etudiant();
                    }
                }
                break;
     
     
     
    // On propose 3 choix(ajouter supprimer ou modiifier  pour la catégorie matière.
     
            case 2 :
                {
                   choix2=Menu_matiere();
     
                   puts("");
                    if (choix2=='a')
                    {
                            Ajouter_matiere();
                            puts("");
     
                    }
                    if (choix2=='b')
                    {
                            Supprimer_matiere();
                    }
                    if (choix2=='c')
                    {
                            Modifier_matiere();
                            puts("");
     
     
                    }
                    else
                    {
                        puts(" VOUS AVEZ FAIT LE MAUVAIS CHOIX.");
                        puts("");
                        choix2=Menu_matiere();
                    }
                }
                break;
     
     
     
    // On propose 3 choix(ajouter supprimer ou modiifier  pour la catégorie évaluation.
     
            case 3 :
                {
                choix3=Menu_evaluation();
     
                    puts("");
                    if (choix3=='a')
                    {
                        Ajouter_evaluation();
                        puts("");
     
                    }
                     else if (choix3=='b')
                    {
                        Supprimer_evaluation();
                    }
                    else if (choix3=='c')
                    {
                        Modifier_evaluation();
                        puts("");
     
     
                    }
                    else
                    {
                        puts(" VOUS AVEZ FAIT LE MAUVAIS CHOIX.");
                        puts("");
                        choix3=Menu_evaluation();
     
                    }
                }
                    break;
     
     
     
    // affichage de la liste des etudiants des matières et evaluations
            case 4 :
                {
                   Afficher();
                   puts("");
                }
            break;
     
    // On recherche un étudiant à partir de son nom et on affiche le résultat
            case 5 :
                {
                   RechercheEtudiant();
                   puts("");
     
                }
            break;
    // On recherche une matière à partir de son Libelle et on affiche le résultat
            case 6 :
                {
                   RechercheMatiere();
                   puts("");
     
                }
            break;
                            /*
    // On calcul la moyenne et l'écart type.
            case 9 :
                printf("Cliquez sur a pour calculer la moyenne.");
                printf("Cliquez sur b pour calculer l'ecart type.");
                scanf("%c",&choix9);
                    switch (choix9)
                    {
                        case 'a' : Moyenne();
                        case 'b' : Ecart_type();
                    }
     
            case 10 :
            case 11 :
            */
    // On quitte le programme .
            case 12 :
     
                      {
                          printf("Merci d'avoir utilise notre service.");
                          exit(0);
                      }
             break;
     
     
     
                }
        }
        return (0);
    }
     
     
     
     
     
    void Ajouter_etudiant()
    {
     
        FILE*fpt;
        etudiant un_etudiant;
    char reponse;
        fpt=fopen("liste_etudiant.txt","w");
        fprintf(fpt,"Numero\t\tNom\t\t\tPrenom\t\tJour\tMois\tAnnee\t\temail\t\t\tCommentaires\n\n");
        do{
     
           srand(time(NULL));
           un_etudiant.numero=Rand();
           fprintf(fpt,"%ld\t\t",un_etudiant.numero);
     
           printf("\n entrez le nom de l'etudiant: ");
           LireChaine(un_etudiant.nom,MAX);
           fprintf(fpt,"%s\t\t\t",un_etudiant.nom);
     
     
           printf("\n entrez le prenom de l'etudiant: ");
           LireChaine(un_etudiant.prenom,MAX);
           fprintf(fpt,"%s\t\t",un_etudiant.prenom);
     
           //viderBuffer();
           printf("\n entrez le jour de naissance: ");
           un_etudiant.date_de_naissance.jour=LireNombreEntier();
           fprintf(fpt,"%ld\t",un_etudiant.date_de_naissance.jour);
     
           printf("\n entrez le mois de naissance: ");
     
           un_etudiant.date_de_naissance.mois=LireNombreEntier();
           fprintf(fpt,"%ld\t",un_etudiant.date_de_naissance.mois);
     
           printf("\n entrez l'annee de naissance: ");
           un_etudiant.date_de_naissance.annee=LireNombreEntier();
           fprintf(fpt,"%ld\t",un_etudiant.date_de_naissance.annee);
     
           printf("\n entrez l'email: ");
            LireChaine(un_etudiant.email,MAX);
           fprintf(fpt,"%s\t\t\t",un_etudiant.email);
     
     
     
           printf("\n entrez les commentaires: ");
           LireChaine(un_etudiant.commentaires, MAX);
           fprintf(fpt,"%s\n",un_etudiant.commentaires);
     
           printf("\n voulez-vous ajouter un autre etudiant? O/N ");
     
           reponse=getche();
     
           puts(" ");
        }while(reponse=='O');
     
        fclose(fpt);
     
     }
     
     
     
     
     
     
    void Supprimer_etudiant()
    {
     
    }
     
    void Modifier_etudiant()
    {
    //viderBuffer();
     int pos=0;
     int choix=0;
      FILE*fb;
     etudiant un_etudiant;
     
      if(NULL == (fb = fopen("liste_etudiant.txt","r")))
      {
        printf("Err %d\n",errno);
        perror(" ");
      }
      if(!NombreEnregistrementsEtudiant())
        return;
      else
        pos = RechercheEtudiant();
     
      if(!pos)
        printf("Opération annulée ou Enregistrement inexistant!\n");
      else{
        fseek(fb,(100 + 100 + sizeof(int))*(pos-1),SEEK_SET);
        printf("---------------------\n");
        printf("| Menu modification |\n");
        printf("---------------------\n");
        printf("   1. Modifier le nom\n   2. Modifier le prénom\n"
               "   3. Modifier le jourNaiss\n  4. Modifier le MoisNaiss\n"
               "   5. Modifier l'AnneNaiss\n   6. Modifier l'Email\n"
               "   7. Modifier les commentaires\n  8. Modifier tout\n"
    	       "   9. Annuler\n");
        printf("Faites votre choix : ");
        choix=LireNombreEntier();
        switch(choix){
          case 1:
    	    printf("Entrez le nouveau nom : ");
    	    LireChaine(un_etudiant.nom,MAX);
    	    fwrite(un_etudiant.nom,100,1,fb);
    	    fclose(fb);
    	    break;
          case 2:
    	    printf("Entrez le nouveau prénom : ");
    	    LireChaine(un_etudiant.prenom,MAX);
    	    fseek(fb,100,SEEK_CUR);
    	    fwrite(un_etudiant.prenom,100,1,fb);
    	    fclose(fb);
    	    break;
          case 3:
    	    printf("Entrez le nouveau jour : ");
    	    un_etudiant.date_de_naissance.jour=LireNombreEntier();
    	    fseek(fb,100+100,SEEK_CUR);
    	    fwrite(&un_etudiant.date_de_naissance.jour,sizeof(int),1,fb);
    	    fclose(fb);
    	    break;
          case 4:
    	    printf("Entrez le nouveau Mois : ");
    	    un_etudiant.date_de_naissance.mois=LireNombreEntier();
    	    fseek(fb,100+100,SEEK_CUR);
    	    fwrite(&un_etudiant.date_de_naissance.mois,sizeof(int),1,fb);
    	    fclose(fb);
    	    break;
          case 5:
    	    printf("Entrez la nouvelle annee: ");
    	    un_etudiant.date_de_naissance.annee=LireNombreEntier();
    	    fseek(fb,100+100,SEEK_CUR);
    	    fwrite(&un_etudiant.date_de_naissance.annee,sizeof(int),1,fb);
    	    fclose(fb);
    	    break;
         case 6:
    	    printf("Entrez le nouveau email: ");
    	    LireChaine(un_etudiant.email,MAX);
    	    fseek(fb,100,SEEK_CUR);
    	    fwrite(un_etudiant.email,100,1,fb);
    	    fclose(fb);
    	    break;
         case 7:
    	    printf("Entrez les nouveaux commentaires : ");
    	    LireChaine(un_etudiant.commentaires,MAX);
    	    fseek(fb,100,SEEK_CUR);
    	    fwrite(un_etudiant.commentaires,100,1,fb);
    	    fclose(fb);
    	    break;
          case 8:
    	    printf("Entrez le nouveau nom : ");
    	    LireChaine(un_etudiant.nom,MAX);
    	    printf("Entrez le nouveau prénom : ");
    	    LireChaine(un_etudiant.prenom,MAX);
    	    printf("Entrez le nouveau Journaiss : ");
    	    un_etudiant.date_de_naissance.jour=LireNombreEntier();
    	    printf("Entrez le nouveau Moisnaiss : ");
    	    un_etudiant.date_de_naissance.mois=LireNombreEntier();
    	    printf("Entrez la nouvelle Annenaiss : ");
    	    un_etudiant.date_de_naissance.annee=LireNombreEntier();
    	    printf("Entrez le nouveau email : ");
    	    LireChaine(un_etudiant.email,MAX);
    	    printf("Entrez les nouveaux Commentaires : ");
    	    LireChaine(un_etudiant.commentaires,MAX);
    	    fwrite(un_etudiant.nom,100,1,fb);
    	    fwrite(un_etudiant.prenom,100,1,fb);
    	    fwrite(&un_etudiant.date_de_naissance.jour,sizeof(int),1,fb);
    	    fwrite(&un_etudiant.date_de_naissance.mois,sizeof(int),1,fb);
    	    fwrite(&un_etudiant.date_de_naissance.annee,sizeof(int),1,fb);
    	    fwrite(un_etudiant.email,100,1,fb);
    	    fwrite(un_etudiant.commentaires,100,1,fb);
    	    fclose(fb);
    	    break;
          case 9:
    	    printf("Opération annulée!\n");
    	    break;
        }
      }
     
    }
     
    void Ajouter_matiere()
     
    {
         FILE*fpt2;
         matiere une_matiere;
        char reponse;
        fpt2=fopen("liste_matiere.txt","a+");
        fprintf(fpt2,"Code_matiere\tLibelle\tCoefficient\n");
     
         do{
     
           une_matiere.code_matiere=Rand();
           fprintf(fpt2,"%ld\t\t",une_matiere.code_matiere);
     
     
           printf("\n entrez le libelle: ");  LireChaine(une_matiere.libelle,MAX); fprintf(fpt2,"%s\t\t",une_matiere.libelle);
     
     
     
           printf("\n entrez le coefficient: "); une_matiere.coefficient=LireNombreEntier();
           fprintf(fpt2,"%ld\n",une_matiere.coefficient);
     
           printf("\n voulez-vous ajouter une autre matiere? O/N: ");
           reponse=getche();
           puts("");
        }while(reponse=='O');
         fclose(fpt2);
    }
     
    void Modifier_matiere()
    {
      int pos=0;
      int choix= 0;
      FILE *fb;
      matiere une_matiere;
     
      if(NULL == (fb = fopen("liste_matiere.txt","r"))){
        printf("Err %d\n",errno);
        perror(" ");
      }
      if(! NombreEnregistrementsMatiere())
        return;
      else
        pos = RechercheMatiere();
     
      if(!pos)
        printf("Opération annulée ou Enregistrement inexistant!\n");
      else{
        fseek(fb,(100 + 100 + sizeof(int))*(pos-1),SEEK_SET);
        printf("---------------------\n");
        printf("| Menu modification |\n");
        printf("---------------------\n");
        printf("   1. Modifier le Libelle\n   2. Modifier le coefficient\n"
    	       "   3. Modifier tout\n         4. Annuler\n");
        printf("Faites votre choix : ");
        choix=LireNombreEntier();
        switch(choix){
          case 1:
    	    printf("Entrez le nouveau Libelle : ");
    	    LireChaine(une_matiere.libelle,MAX);
    	    fwrite(une_matiere.libelle,100,1,fb);
    	    fclose(fb);
    	    break;
          case 2:
    	    printf("Entrez le nouveau Coefficient : ");
    	    une_matiere.coefficient=LireNombreEntier();
    	    fseek(fb,100+100,SEEK_CUR);
    	    fwrite(&une_matiere.coefficient,sizeof(int),1,fb);
    	    fclose(fb);
    	    break;
          case 3:
    	    printf("Entrez le nouveau Libelle : ");
    	    LireChaine(une_matiere.libelle,MAX);
    	    printf("Entrez le nouveau Coefficient : ");
    	    une_matiere.coefficient=LireNombreEntier();
    	    fwrite(une_matiere.libelle,100,1,fb);
    	    fwrite(&une_matiere.coefficient,sizeof(int),1,fb);
    	    fclose(fb);
    	    break;
          case 4:
    	    printf("Opération annulée!\n");
    	    break;
        }
      }
     
    }
     
    void Supprimer_matiere()
    {
      matiere une_matiere;
    }
     
    void Ajouter_evaluation()
    {
         FILE*fpt3;
         evaluation une_evaluation;
        char reponse;
        fpt3=fopen("liste_evaluation.txt","a+");
        fprintf(fpt3,"Jour_Eva\tMois_Eva\tAnnée_Eva\tNumero_Etu\tCode_ma\tNote_Etu\n");
         do{
     
           printf("\n entrez le jour de l'evaluation: ");une_evaluation.date_evaluation.jour=LireNombreEntier();
           fprintf(fpt3,"%ld\t",une_evaluation.date_evaluation.jour);
     
           printf("\n entrez le mois de l'evaluation: ");une_evaluation.date_evaluation.mois=LireNombreEntier();
           fprintf(fpt3,"%ld\t",une_evaluation.date_evaluation.mois);
     
           printf("\n entrez l'annee de l'evaluation: ");une_evaluation.date_evaluation.annee=LireNombreEntier();
           fprintf(fpt3,"%ld\t",une_evaluation.date_evaluation.annee);
     
     
           printf("\n entrez le numero etudiant : ");une_evaluation.numero_etudiant=LireNombreEntier();
           fprintf(fpt3,"%ld\t",une_evaluation.numero_etudiant);
     
           printf("\n entrez le code matiere: "); une_evaluation.code_matiere=LireNombreEntier();
           fprintf(fpt3,"%ld\t",une_evaluation.code_matiere);
     
           printf("\n entrez la note: "); une_evaluation.note=LireNombreDecimal();
           fprintf(fpt3,"%lf\t",une_evaluation.note);
     
           printf("\n voulez-vous ajouter une autre matiere? O/N ");
           reponse=getche();
           puts("");
        }while(reponse=='O');
         fclose(fpt3);
    }
     
    int LireNombreEntier()
    {
        char chaine[64];
        fgets(chaine,64,stdin);
        return atoi(chaine);
    }
    float LireNombreDecimal()
    {
        char chaine[64];
        fgets(chaine,64,stdin);
        return atof(chaine);
    }
    void LireChaine(char chaine[], int size)
    {
        fgets(chaine,size,stdin);
        chaine[strlen(chaine)-1]='\0';
     
    }
     
    void viderBuffer()
    {
        int c = 0;
        while (c != '\n' && c != EOF)
        {
            c = getche();
        }
    }
    int Rand()
    {   int i,nombre;
    	float nombre_aleatoire;
    	float borne_minimale = 10150;
    	float borne_maximale = 20150;
        srand(time(NULL));
    	for(i=0; i<100; i++)
    	{
     
    	nombre_aleatoire = rand();
            nombre= (int)(nombre_aleatoire * (borne_maximale+1 - borne_minimale) / RAND_MAX + borne_minimale );
     
    	}
    	return(nombre);
    }
     
     
    void Supprimer_evaluation()
    {
       evaluation une_evaluation;
    }
     
    void Modifier_evaluation()
    {
      evaluation une_evaluation;
    }
     
    int Menu_Principal()
    {
        //Services 1 à 4.
     
        int choi;
     
        puts("******************************MENU PRINCIPAL********************************");
        puts("");
        puts("****************************************************************************");
        puts("");
        puts("Selectionnez un des services suivants en cliquant sur le numero intrinseque:");
        puts("");
        puts("1 : Ajouter,supprimer,modifier un etudiant.");
        puts("2 : Ajouter,supprimer,modifier une matiere.");
        puts("3 : Ajouter,supprimer,modifier un evaluation.");
        puts("4 : Afficher la liste des etudiants, matieres et evaluations.");
        puts("5 : Rechercher un Etudiant a partiir du nom.");
        puts("6 : Rechercher une matière a partir du libele.");
        //Services 9 à 12.
        puts("9 : Calculer la moyenne et l'ecart type par matiere.");
        puts("10 : Charger une base sauvegardee sur disque.");
        puts("11 : Enregistrer la base sur disque.");
        puts("12 : Quitter.");
        puts("");
        printf("Votre choix:");
        choi=LireNombreEntier();
        return(choi);
    }
     
    char Menu_etudiant()
    {   char choi;
        puts("*********************MENU GESTIONNAIRE ETUDIANTS********************");
        puts("");
        puts("********************************************************************");
        puts("");
        puts("1 : Cliquez a pour ajouter un etudiant.");
        puts("2 : Cliquez b pour supprimer un etudiant.");
        puts("3 : Cliquez c pour modifier un etudiant.");
        puts("");
        printf("Votre choix:");
        choi=getche();
        return(choi);
     
     
    }
     
    char Menu_matiere()
    {   char choi;
        puts("*********************MENU GESTIONNAIRE MATIERES********************");
        puts("");
        puts("*******************************************************************");
        puts("");
        puts("1 : Cliquez a pour ajouter une matiere.");
        puts("2 : Cliquez b pour supprimer un matiere.");
        puts("3 : Cliquez c pour modifier un matiere.");
        puts("");
        printf("Votre choix:");
        choi=getche();
        return(choi);
    }
     
    char Menu_evaluation()
    {   char choi;
        puts("*********************MENU GESTIONNAIRE EVALUATIONS*****************");
        puts("");
        puts("*******************************************************************");
        puts("");
        puts("1 : Cliquez a pour ajouter une evaluation.");
        puts("2 : Cliquez b pour supprimer une evaluation.");
        puts("3 : Cliquez c pour modifier une evaluation.");
        puts("");
        printf("Votre choix:");
        choi=getche();
        return(choi);
    }
    int NombreEnregistrementsEtudiant()
    {
      FILE*fb;
     
      int nb = 0;
      etudiant un_etudiant;
     
      if(NULL == (fb = fopen("liste_etudiant.txt","r"))){
        printf("Err %d\n",errno);
        perror(" ");
      }else{
        while(fread(&un_etudiant.numero,sizeof(int),1,fb)&&
          fread(un_etudiant.nom,100,1,fb) == 1 &&
          fread(un_etudiant.prenom,100,1,fb) == 1 &&
          fread(&un_etudiant.date_de_naissance.jour,sizeof(int),1,fb) &&
          fread(&un_etudiant.date_de_naissance.mois,sizeof(int),1,fb) &&
          fread(&un_etudiant.date_de_naissance.annee,sizeof(int),1,fb) &&
          fread(un_etudiant.email,100,1,fb) == 1 &&
          fread(un_etudiant.commentaires,100,1,fb)== 1)
            nb++;
      fclose(fb);
      }
      return nb;
    }
    int NombreEnregistrementsMatiere(){
      FILE*fb;
      matiere une_matiere;
      int nb = 0;
     
      if(NULL == (fb = fopen("liste_matiere.txt","r"))){
        printf("Err %d\n",errno);
        perror(" ");
      }else{
        while(fread(&une_matiere.code_matiere,sizeof(int),1,fb) &&
          fread(une_matiere.libelle,100,1,fb) == 1 &&
          fread(&une_matiere.coefficient,sizeof(int),1,fb))
            nb++;
      fclose(fb);
      }
      return nb;
    }
    int NombreEnregistrementsEvaluation(){
      FILE *fb;
      evaluation une_evaluation;
      int nb = 0;
     
      if(NULL == (fb = fopen("liste_evaluation.txt","r"))){
        printf("Err %d\n",errno);
        perror(" ");
      }else{
        while(fread(&une_evaluation.date_evaluation.jour,sizeof(int),1,fb) &&
              fread(&une_evaluation.date_evaluation.mois,sizeof(int),1,fb) &&
              fread(&une_evaluation.date_evaluation.annee,sizeof(int),1,fb) &&
              fread(&une_evaluation.numero_etudiant,sizeof(int),1,fb) &&
              fread(&une_evaluation.code_matiere,sizeof(int),1,fb) &&
              fread(&une_evaluation.note,sizeof(int),1,fb))
            nb++;
      fclose(fb);
      }
      return nb;
    }
    int RechercheEtudiant()
    {
      FILE*fb;
      etudiant un_etudiant;
      char nom[100];
      int i,choix,nbe;
     
      printf("------------------------------------------\n");
      printf("| Rechercher l'enregistrement à modifier |\n");
      printf("------------------------------------------\n");
      printf("   1. Recherche par nom\n    ");
      printf("   2. Annuler\nFaites votre choix : ");
     
      choix=LireNombreEntier();
     
      if(NULL == (fb = fopen("liste_etudiant.txt","r"))){
        printf("Err %d\n",errno);
        perror(" ");
      }
       nbe=NombreEnregistrementsEtudiant();
      if(! nbe)
    	  return 0;
      else{
        switch(choix){
          case 1:
    	    printf("Entrez nom : ");
    	    LireChaine(nom,MAX);
    	    for(i=1;i<=nbe;i++){
                fread(&un_etudiant.numero,sizeof(int),1,fb);
                fread(un_etudiant.nom,100,1,fb);
                fread(un_etudiant.prenom,100,1,fb);
                fread(&un_etudiant.date_de_naissance.jour,sizeof(int),1,fb);
                fread(&un_etudiant.date_de_naissance.mois,sizeof(int),1,fb);
                fread(&un_etudiant.date_de_naissance.annee,sizeof(int),1,fb);
                fread(un_etudiant.email,100,1,fb);
                fread(un_etudiant.commentaires,100,1,fb);
    	      if( strcmp(nom,un_etudiant.nom)==0){
                    printf("NumeroEtudiant : %ld, Nom : %ls, Prenom: %ls, Journaiss : %ld, Moisnaiss : %ld, Anneenaiss : %ld, Email : %ls, Commentaires : %ls\n",
    			un_etudiant.numero,un_etudiant.nom,un_etudiant.prenom,un_etudiant.date_de_naissance.jour,un_etudiant.date_de_naissance.mois,un_etudiant.date_de_naissance.annee,un_etudiant.email,un_etudiant.commentaires);
    		fclose(fb);
    		return i;
    	      }
    	    }
    	    return 0;
    	    break;
          case 2:
    	    return 0;
    	    break;
          default:
    	    return 0;
    	    break;
        }
      }
    }
    int RechercheMatiere(){
      FILE *fb;
        matiere une_matiere;
      char nomMatiere[100];
      int i,choix;
     
      printf("------------------------------------------\n");
      printf("| Rechercher l'enregistrement à modifier |\n");
      printf("------------------------------------------\n");
      printf("   1. Recherche par libelle\n    ");
      printf("   2. Annuler\nFaites votre choix : ");
      choix=LireNombreEntier();
     
      if(NULL == (fb = fopen("liste_matiere.txt","r"))){
        printf("Err %d\n",errno);
        perror(" ");
      }
      if(! NombreEnregistrementsMatiere())
    	  return 0;
      else{
        switch(choix){
          case 1:
    	    printf("Entrez Libelle : ");
    	    LireChaine(nomMatiere,MAX);
    	    for(i=1;i<=NombreEnregistrementsMatiere();++i){
                fread(&une_matiere.code_matiere,sizeof(int),1,fb);
                fread(une_matiere.libelle,100,1,fb);
                fread(&une_matiere.coefficient,sizeof(int),1,fb);
    	      if( strcmp(nomMatiere,une_matiere.libelle)==0){
                    printf("CodeMatiere : %ld, Libelle : %ls, Coefficient : %ld\n",
    			une_matiere.code_matiere,une_matiere.libelle,une_matiere.coefficient);
    		fclose(fb);
    		return i;
    	      }
    	    }
    	    return 0;
    	    break;
          case 2:
    	    return 0;
    	    break;
          default:
    	    return 0;
    	    break;
        }
      }
    }
    void  Afficher()
    {
     
    }
    Je vous remercie

  2. #2
    Membre prolifique
    Avatar de Sve@r
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2006
    Messages
    12 867
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 12 867
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par Patrickol12 Voir le message
    Bonjour,

    voici le code de mon projet en C je voudrais faire un gestionnaire d'étudiants où je peux ajouter un étudiant, modifier ou le supprimer même chose pour des matières mais je suis coincé. Ma fonction ajouter marche bien mais quand j'appelle ma fonction modifier le programme retourne au menu principal je ne sais pas pourquoi?
    Bonjour
    Parce que ta fonction NombreEnregistrementsEtudiant() renvoie 0. Tu l'aurais vu si tu avais ajouté un simple printf() en ligne 327.
    Et si ta fonction renvoie 0, c'est peut-être parce que tu utilises fread() avec des paramètres pour lire du binaire alors que tu lis un fichier texte...

    Accessoirement, tu n'as pas l'impression que tous tes menus c'est un peu répétitif ? "ajouter un truc", "modifier un truc", "supprimer un truc"... Tu n'aurais pas pu faire un seul menu plus générique ???
    Mon Tutoriel sur la programmation «Python»
    Mon Tutoriel sur la programmation «Shell»
    Sinon il y en a pleins d'autres. N'oubliez pas non plus les différentes faq disponibles sur ce site
    Et on poste ses codes entre balises [code] et [/code]

Discussions similaires

  1. [PROJET]LinCopier - Gestionnaire de copie évolué pour Linux
    Par Sherwood51 dans le forum Général Python
    Réponses: 13
    Dernier message: 25/10/2010, 03h27
  2. Présentation d'un projet de gestionnaire de fenêtres en javascript.
    Par Raph76 dans le forum Général JavaScript
    Réponses: 18
    Dernier message: 26/08/2008, 12h55
  3. [Outil] Quel Gestionnaire de bugs choisir pour les projets ?
    Par MLK jr dans le forum Langages de programmation
    Réponses: 21
    Dernier message: 06/06/2006, 16h39
  4. Gestionnaire de projet
    Par localhost dans le forum Langages de programmation
    Réponses: 3
    Dernier message: 02/11/2004, 11h52

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