Bonsoir !
je souhaite ecrire dans un fichier un tableau de structure;rempli par des informations fournies au clavier.
J'ai commencé par remplir mon tableau ensuite le recopier d'un coup dans mon fichier.
voila ce que j'ai fait:

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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define lg_file 100
#define nb_enfant_max 5
 
/*********** definition variable de type struct *******/
 
struct person {
    char nom, prenom;
    int enfant;
    int age_enfant[nb_enfant_max];
};
 
/*************   debut  *******************/
 
main()
 
/************** declaration des variables********/
{
    char file_name[lg_file + 1];
    FILE *fichier;
    struct person tab[3];
    int taille_tableau = 3 * sizeof(struct person);
    int i;
    int j;
 
 
/************** ouverture d'un fichier en ecriture ********/
 
    printf("entrez le nom de votre fichier: \n");
    gets(file_name);
 
    if ((fichier = fopen(file_name, "w")) == NULL) {
        printf("ouverture echouée");
        exit(-1);
    }
 
/************* implementation de mon tableau************/
 
    for (i = 0; i < 3; i++) {
        printf("entrez le nom de votre client:");
        scanf("%c", tab[i].nom);
 
        printf("entrez le nom prenom votre client:");
        scanf("%c", tab[i].prenom);
 
        printf("entrez le nombre d'enfant de votre client:");
        scanf("%d", tab[i].enfant);
 
        for (j = 0; j < 5 && j < tab[i].enfant; j++)
        {
 
            printf("entrez l'age du % d enfant de votre client:", j + 1);
            scanf("%d", tab[i].age_enfant[j]);
        }
 
/****************** ecriture fichier ***************/
 
        fwrite(tab, taille_tableau, 1, fichier);
 
 
/****************** fin creation ***************/
 
        fclose(fichier);
 
    }
}
Voila j'ai essayé;mais j'y arrive pas

Si vs trouvez mon code bizarre, ne m'en voulez pas ;chui debutante en c