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 :

problème appel fonction


Sujet :

C

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Inscrit en
    Novembre 2012
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Novembre 2012
    Messages : 25
    Par défaut problème appel fonction
    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
     
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "gestionpatient.h"
    
    int gestionpatient()
    {
         char chemin[]="/home/3omda/gestionpatient.txt";
         int n,m;
         char c[100];
     do
        {
            system("clear");
        m=menugestionpatient();
        switch (m)
        {
            case 1 :
             system("clear");
             printf(" donner le nombre de patient à ajouter \n ");
             scanf("%d",&n);
             creerFichierpatients(chemin,n);
             system("clear");
             break ;
    
             case 2 :
              system("clear");
              afficherListepatients(chemin);
              printf(" \n \n appuyer sur une lettre pour retourner au menu: ");
              fflush(stdin);
              scanf("%s",c);
              system("clear");
              break ;
    
              case 3 :
              system("clear");
              recherchepatient(chemin);
              printf(" retour au menu \n \n \n appuyer sur une touche ");
              system("clear");
              break ;
    
              case 4 :
              system("clear");
              supprimerpatient(chemin);
              system("clear");
              break ;
    
              default :
              system("clear");
              printf("retour au menu principale \n");
              main();
        }
        }
         while (m>0 || m<5 );
    return 0;
    }
    
    
    
    //------------------------------------------------------------------------------
    //******************************************************************************
    //ces fonctions permettent de rechercher & d'afficher un patient selon 7 critères au choix
    
    int choix ()
    {
        int x;
      do
        {
        printf(" 1 ---> recherche par nom \n ");
        printf(" 2 ---> recherche par prenom \n ");
        printf(" 3 ---> recherche par age \n ");
        printf(" 4 ---> recherche par numero de telephone  \n ");
        printf(" 5 ---> rehcerche par adresse \n ");
        printf(" 6 ---> rehcerche par rendezvous  \n ");
        printf(" 7 ---> rehcerche par nom, prenom,age,numero de telephone, rendezvous et adresse \n ");
        printf(" 0 ---> retour au menu : gestion patient \n ");
        printf("\n \n ");
        printf(" donner votre choix \n ");
        fflush(stdin);
        scanf("%d",&x);
        }
        while (x<0 || x>7);
        return x;
    }
    //***********************************************************************************
    //***************************************************************
    
    void recherchepatient(char chemin[])
    {
        char nom[100];
        char prenom[100];
        char rendezvous[100];
        char adresse[100];
        int telephone ;
        int age,exist=0 ;
        char x ,c[100];
    
       FILE *f;
       patient p ;
    
     do
     {
     x=choix();
     switch (x) {
    
            case 1 :
    
        system("clear");
        printf(" donner le nom de patient :\n");
        fflush(stdin);
        scanf("%s",nom);
        system("clear");
        f=fopen(chemin,"r");
        if (f==NULL)
        {
        printf(" erreur le chemin %s est erroné \n ",chemin);
        }
        while (fscanf(f,"%s  %s  %d  %d  %s  %s \n",p.nom,p.prenom,&p.telephone,&p.age,p.adresse,p.rendezvous)!=EOF)
        {
        if ((strcmp(p.nom,nom)== 0))
       {
        printf(" le patient existe \n \n \n ");
        afficherpatient(p);
         exist=1;
       }
     }
        if (exist== 0)
        {
            printf(" \n \n erreur !! le patient n'existe pas !!! \n \n");
        }
        printf(" \n \n \n appuyer sur une lettre pour retourner au menu: ");
        fflush(stdin);
        scanf("%s",c);
        fclose(f);
        exist=0;
        system("clear");
        break ;
    
        case 2 :
    
        system("clear");
        printf(" donner le prenom de patient :\n");
        fflush(stdin);
        scanf("%s",prenom);
         system("clear");
         f=fopen(chemin,"r");
         if (f==NULL)
         {
         printf(" erreur le chemin %s est erroné \n ",chemin);
         }
         while (fscanf(f,"%s  %s  %d  %d  %s  %s \n",p.nom,p.prenom,&p.telephone,&p.age,p.adresse,p.rendezvous)!=EOF)
         {
         if ((strcmp(p.prenom,prenom)== 0))
         {
        printf(" le patient existe \n ");
        afficherpatient(p);
       }
     }
        if (exist==0)
        {
            printf(" \n \n erreur !! le patient n'existe pas !!! \n \n");
        }
        printf(" \n \n \n appuyer sur une lettre pour retourner au menu: ");
        fflush(stdin);
        scanf("%s",c);
        fclose(f);
        exist=0;
        system("clear");
        break ;
    
       case 3 :
    
        system("clear");
        printf(" donner l'age de patient :\n");
        fflush(stdin);
        scanf("%d",&age);
         system("clear");
         f=fopen(chemin,"r");
         if (f==NULL)
         {
         printf(" erreur le chemin %s est erroné \n ",chemin);
         }
         while (fscanf(f,"%s  %s  %d  %d  %s  %s \n",p.nom,p.prenom,&p.telephone,&p.age,p.adresse,p.rendezvous)!=EOF)
         {
         if (p.age==age)
       {
        printf(" le patient existe \n ");
        afficherpatient(p);
        exist=1;
       }
     }
        if (exist== 0)
        {
            printf(" \n \n erreur !! le patient n'existe pas !!! \n \n ");
        }
        printf(" \n \n \n appuyer sur une lettre pour retourner au menu: ");
        fflush(stdin);
        scanf("%s",c);
        fclose(f);
        exist=0;
        system("clear");
        break ;
    
        case 4 :
    
        system("clear");
        printf(" donner le numero de telephone de patient :\n");
        fflush(stdin);
        scanf("%d",&telephone);
         system("clear");
         f=fopen(chemin,"r");
         if (f==NULL)
         {
         printf(" erreur le chemin %s est erroné \n ",chemin);
         }
     while (fscanf(f,"%s  %s  %d  %d  %s  %s \n",p.nom,p.prenom,&p.telephone,&p.age,p.adresse,p.rendezvous)!=EOF)
     {
      if ((p.telephone==telephone))
       {
        printf(" le patient existe \n ");
        afficherpatient(p);
         exist=1;
       }
     }
     if (exist== 0)
        {
            printf(" \n \n erreur !! le patient n'existe pas !!! \n \n");
        }
        printf(" \n \n \n appuyer sur une lettre pour retourner au menu: ");
        fflush(stdin);
        scanf("%s",c);
        fclose(f);
        exist=0;
        system("clear");
        break ;
        case 5 :
    
        system("clear");
        printf(" donner l'adresse de patient :\n");
        fflush(stdin);
        scanf("%s",adresse);
         system("clear");
         f=fopen(chemin,"r");
         if (f==NULL)
         {
         printf(" erreur le chemin %s est erroné \n ",chemin);
         }
     while (fscanf(f,"%s  %s  %d  %d  %s  %s \n",p.nom,p.prenom,&p.telephone,&p.age,p.adresse,p.rendezvous)!=EOF)
     {
      if ((strcmp(p.adresse,adresse)== 0))
       {
        printf(" le patient existe \n ");
        afficherpatient(p);
         exist=1;
       }
     }
       if (exist== 0)
        {
            printf(" \n \n erreur !! le patient n'existe pas !!! \n \n");
        }
        printf(" \n \n \n appuyer sur une lettre pour retourner au menu: ");
        fflush(stdin);
        scanf("%s",c);
        fclose(f);
        exist=0;
        system("clear");
        break ;
    
        case 6 :
    
        system("clear");
        printf(" donner le rendez vous de patient :\n");
        fflush(stdin);
        scanf("%s",rendezvous);
         system("clear");
         f=fopen(chemin,"r");
        if (f==NULL)
        {
        printf(" erreur le chemin %s est erroné \n ",chemin);
        }
     while (fscanf(f,"%s  %s  %d  %d  %s  %s \n",p.nom,p.prenom,&p.telephone,&p.age,p.adresse,p.rendezvous)!=EOF)
     {
      if ((strcmp(p.rendezvous,rendezvous)== 0))
       {
        printf(" le patient existe \n ");
        afficherpatient(p);
         exist=1;
       }
     }
     if (exist== 0)
        {
            printf(" \n \n erreur !! le patient n'existe pas !!! \n \n");
        }
        printf(" \n \n \n appuyer sur une lettre pour retourner au menu: ");
        fflush(stdin);
        scanf("%s",c);
        fclose(f);
        exist=0;
        system("clear");
        break ;
    
       case 7 :
       system("clear");
        printf(" donner le nom de patient :\n");
        fflush(stdin);
        scanf("%s",nom);
        printf(" donner le prenom de patient :\n");
        fflush(stdin);
        scanf("%s",prenom);
        printf(" donner l'age de patient :\n");
        fflush(stdin);
        scanf("%d",&age);
        printf(" donner le numreo de telephone :\n");
        fflush(stdin);
        scanf("%d",&telephone);
        printf(" donner l'adresse de patient :\n");
        fflush(stdin);
        scanf("%s",adresse);
        printf(" donner le rendez vous de patient :\n");
        fflush(stdin);
        scanf("%s",rendezvous);
         system("clear");
         f=fopen(chemin,"r");
        if (f==NULL)
        {
        printf(" erreur le chemin %s est erroné \n ",chemin);
        }
    
       while (fscanf(f,"%s  %s  %d  %d  %s  %s \n",p.nom,p.prenom,&p.telephone,&p.age,p.adresse,p.rendezvous)!=EOF)
     {
      if ((strcmp(p.nom,nom)== 0) && (strcmp(p.prenom,prenom)== 0) && (strcmp(p.rendezvous,rendezvous)== 0) && (p.telephone==telephone) && (strcmp(p.adresse,adresse)==0))
       {
        printf(" le patient existe \n ");
        afficherpatient(p);
         exist=1;
       }
    
     }
     if (exist==0)
        {
            printf(" \n \n erreur !! le patient n'existe pas !!! \n \n");
        }
      printf(" \n \n \n appuyer sur une lettre pour retourner au menu: ");
        fflush(stdin);
        scanf("%s",c);
        fclose(f);
        exist=0;
        system("clear");
        break ;
    
            default :
            system("clear");
            fclose(f);
            gestionpatient();
      }
     }while (x>0 || x<7);
    }

    salut j'ai une petie problème d'appel de fonction dont je n'ai pas compris la faute !!!

    en effet la fonction gestionpatient appelle la fonction void recherche patient pour effectuer différent manipulation de recherche selon un menu au choix : l'option =0 permet de sortir de la fonction recherche patient et retourner au debut de la fonction gestion patient qui contient plusieurs menu et cela l'aide de l'appel de la fonction dans la case default ; le probleme est au lieu de revenir au debut gestion patient le programme plante et fait un exit !!!!! je ne sait pas pourquoi !!

    comment stopper le traitement et revenir à la fonction appelante ???

    bon j'utilise codeblocks comme compilateur sous fedora 18

  2. #2
    Modérateur

    Avatar de Bktero
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2009
    Messages
    4 493
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2009
    Messages : 4 493
    Billets dans le blog
    1
    Par défaut
    Salut

    Si je compile ton code, j'obtiens ceci :
    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
    gccw declare_first.c 
    declare_first.c:6:28: error: gestionpatient.h: No such file or directory
    declare_first.c: In function ‘gestionpatient’:
    declare_first.c:16: warning: implicit declaration of function ‘menugestionpatient’
    declare_first.c:23: warning: implicit declaration of function ‘creerFichierpatients’
    declare_first.c:29: warning: implicit declaration of function ‘afficherListepatients’
    declare_first.c:38: warning: implicit declaration of function ‘recherchepatient’
    declare_first.c:45: warning: implicit declaration of function ‘supprimerpatient’
    declare_first.c:52: warning: implicit declaration of function ‘main’
    declare_first.c: At top level:
    declare_first.c:90: warning: conflicting types for ‘recherchepatient’
    declare_first.c:38: warning: previous implicit declaration of ‘recherchepatient’ was here
    declare_first.c: In function ‘recherchepatient’:
    declare_first.c:100: error: ‘patient’ undeclared (first use in this function)
    declare_first.c:100: error: (Each undeclared identifier is reported only once
    declare_first.c:100: error: for each function it appears in.)
    declare_first.c:100: error: expected ‘;’ before ‘p’
    declare_first.c:119: error: ‘p’ undeclared (first use in this function)
    declare_first.c:124: warning: implicit declaration of function ‘afficherpatient’
    Peux-tu nous fournir le contenu du fichier "gestionpatient.h" pour vérifier qu'il fait bien disparaitre ces problèmes de compilation ?

    De plus, pourrais-tu réduire un peu la quantité de code, en le laissant que les fonctions qui posent soucis et en enlevant ce qui fonctionne correctement ?

  3. #3
    Membre actif
    Homme Profil pro
    Inscrit en
    Novembre 2012
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Novembre 2012
    Messages : 25
    Par défaut
    Citation Envoyé par Bktero Voir le message
    Salut


    Peux-tu nous fournir le contenu du fichier "gestionpatient.h" pour vérifier qu'il fait bien disparaitre ces problèmes de compilation ?

    De plus, pourrais-tu réduire un peu la quantité de code, en le laissant que les fonctions qui posent soucis et en enlevant ce qui fonctionne correctement ?

    merci !!! j'ai trouvé la faute !! en effet c'est le fclose(f) qui est responsable et c'est naturel car pour chaque itération case j'ouvre et je ferme le fichier et lors du passage à l'itération default il n y a pas de fichier ouvert pour le fermer pour cela le programme plante a3333333333 !!!!!!

    je doit ouvrir les yeux chaque fois que je modifie le code !!!!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2000] Problème appel fonction
    Par keks42 dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 24/02/2010, 12h37
  2. [OL-2003] Problème appel fonction
    Par ptitemeuh dans le forum VBA Outlook
    Réponses: 0
    Dernier message: 04/02/2010, 15h26
  3. [OL-2003] Problème appel fonction
    Par ptitemeuh dans le forum Outlook
    Réponses: 0
    Dernier message: 04/02/2010, 15h26
  4. Problème appel fonction
    Par Elstak dans le forum VC++ .NET
    Réponses: 11
    Dernier message: 22/05/2009, 19h37
  5. [PHP-JS] problème appel fonction javascript
    Par OLman135 dans le forum Langage
    Réponses: 5
    Dernier message: 14/05/2009, 21h30

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