bonjour, j'ai un problème avec mon programme, que je réalise d'après les exercices de cette page :
http://inferno.cs.univ-paris8.fr/~am...12.html#ss12.5
La première partie, c'est à dire les questions 1 , 2 , 3 , 4 , 5 , 6 , 7 sont bien faites, mais le reste ne marche pas. Je poste mon premier code dans le fichier struct_1234567.c et celui qui pose problème dans le fichier struct_8.c.

Voilà le code de struct_8.c :

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
/***************************************************************************
 *            struct.c
 *
 *  Sun Jan 27 12:05:36 2008
 *  exercice issu de http://inferno.cs.univ-paris8.fr/~am/tutorial/C/Cours-12.html#ss12.5
 ****************************************************************************/
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
 
struct Personne
{
    char nom[32];
    char num_tel[16];
};
 
struct Carnet
{
    struct Personne annuaire[20];
    int compteur;
};
 
struct Personne cree_personne(char *, char*);
 
void affiche_carnet(struct Carnet carnet_in);
 
void purger(void);
 
int main(void)
{
    int i;
    struct Carnet mon_carnet;
    char nom[32];
    char tel[16];
    int choix;
    mon_carnet.compteur=0;
 
    do{
        puts("0: quitter le programme");
        puts("1: ajouter une entree");
        puts("2: voir le carnet entier");
        choix = fgetc(stdin);
        purger();
        if(choix=='1')
        {
            puts("nom ? ");
            fgets(nom,32,stdin);
            puts("tel. ? ");
            fgets(tel,16,stdin);
            mon_carnet.annuaire[i]=cree_personne(nom,tel);
            mon_carnet.compteur++;
        }
        else if(choix=='2')
        {
 
                affiche_carnet(mon_carnet);
        }
 
    }while(!(choix=='0'));
    puts("appuyez sur une touche pour continuer");
    getchar();
    return 0;
}
 
 
struct Personne cree_personne(char nom[], char num_tel[])
{
    struct Personne resultat;
    strncpy(resultat.nom,nom,32);
    strncpy(resultat.num_tel,num_tel,16);
    return resultat;
}
 
void affiche_carnet(struct Carnet carnet_in)
{
    int i;
    struct Personne personne_in;
    for(i=0;i<carnet_in.compteur;i++)
    {
        personne_in=carnet_in.annuaire[i];
        printf("nom : %s , tel : %s\n",personne_in.nom,personne_in.num_tel);
    }
}
 
void purger(void)
{
    int c;
    while( (c=getchar())!='\n' && c!=EOF );
}