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 :

[debutant]probleme de sauvetage en fichier binaire


Sujet :

C

  1. #1
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Points : 26
    Points
    26
    Par défaut [debutant]probleme de sauvetage en fichier binaire
    bonjour j'ai fait un petit programme avec sauvetage au format binaire mais voila quand je sauve mon fichier il le crée mais ne copie rien dedans voici mon 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
     
    #include <conio.h>
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #define maxetu 25
    #define maxcotes 3
     
    struct etu
    {
           int 	mat;
           char 	nom[20];
           float 	cote[maxcotes];
    }       tab[maxetu]   ;
     
    struct cotes
    {
    	float	c1;
    	float 	c2;
    	float 	c3;
    }   ;
    char	cha='Z';
    int	i;
    FILE *entree;
    //**************************************************************
    int  lire_float (char nbf[5])
    {
           //	char nbf[5];
    	float nbref;
    	do {
    	gets (nbf);fflush(stdin);
    	nbref = atof (nbf);
    	}
    	while (nbref!=0);
    	return (nbref);
    }
    //**************************************************************
    int lire_int(char nbi[5])
    {
         //	char 	nbi[5];
    	int 	nbrei;
    	do {      fflush(stdin);
    	gets(nbi);
    	nbrei= atoi (nbi);
    	}
    	while (nbrei!=0);
    	return (nbrei);
    }
    //**************************************************************
     
    int lire_mat ( int  m)
    { char 	matt[5];int trouve =0;
    /*
    for (i=0;i<maxetu ;i++)
    	{if ( m == tab[i].mat)
    	       {
    		printf (" matricule deja utilise \n");
    		printf (" entrez un nouveau matricule : \n");
    		fflush(stdin);
    		gets(matt);tab[i].mat=lire_int(matt);m=tab[i].mat;
    	       }
    	}    return (m);
           */
    	for (i=0;i<maxetu;i++)
    	{	if (m==tab[i].mat) trouve =1;
    		else trouve = 0;
    	}
    if (trouve == 0) return 1;
    else return 2;
        //		scanf (" %d" , &tab[i].mat );
    }
     
    //**************************************************************
     
    void lire_cotes ( float c)
    {
    if ((c<0)||(c>20))
     {	printf (" entrez autre cotes :");
    	scanf (" %f", &c);}
    	else ;
    }
     
    //*************************************************************
     
    void init (etu *tab)    // ou tab[]
    {
    for (i=0;i<25;i++)
    	{strcpy ("null",tab[i].nom) ;
    	 for (int j=0;j<3;j++)
    	 tab[i].cote[j]=0.0;
    	}
    }
     
    //*************************************************************
     
    void rajoute ( etu *tab)
    {               clrscr();
    	int 	m;
    	char 	matric[5], cot [5];
    	char 	a[3],b,c;
    	int 	j,k,l;
    	int 	tmp ;
    fflush(stdin);
    	printf (" entrez un matricule 0 pour sortir :\n");
    	gets (a);
    while (a[0]!='0')
    {
    	tab[i].mat =atoi(a); k=i;
    	tmp= atoi(a);
    	for  (l=0;l<maxetu && l!=k;l++)
    		{ if (tab[l].mat==tmp) {
    				      printf ("autre matricule :\n");
    				      gets (a);
    				      tab[i].mat= atoi (a);
    		}                     }
     
     
     printf (" entrez le nom de l'etudiant :\n");
     gets (tab[i].nom);
     for (j=0;j<3;j++)
    	{ printf (" entrez la cote nø %d : ",j+1);
    	fflush(stdin);
    	gets (a); tab[i].cote[j]=atoi (a);
    	}
    	i++;
     
     do
     {
     fflush(stdin);
     printf (" entrez le matricule de l'etudiant suivant  0 pour sortir :\n");
     gets (a);
     }
     while ((lire_mat(atoi(a))!=1)&&(atoi(a)!=0));
    }
    }
    //***************************************************************
     
    void afficher (etu * tab )
    {                    clrscr();
    for (i=0;i<25 && tab[i].mat!=0;i++)
    {
    	printf ("%d\t %s\t", tab[i].mat, tab[i].nom );
    	for (int j=0;j<maxcotes;j++)
    		printf (" %3.1f ", tab[i].cote[j]);
    puts (" \n");
    }
    getch();
    }
     
    //****************************************************************
    void ouverture()
    {	etu	tab1[25];
    FILE 	*entree;
    i=0;
    for (int j=0;j<maxetu;j++);
    	{
    	tab1[j].mat=0;
    	strcpy (tab1[j].nom,NULL);
    	}
    entree = fopen ("c:\\marc", "rb+");
    if( !entree)
           {
    	puts (" erreur d'ouverture de fichier\n");
    	getch();
    	}
    else
    	{
    	if (fread (&tab1[i],sizeof(struct etu),25,entree)>0)
    	{
    		while (i<25 && tab[i].mat!=0 )
     
    		{
    		if (tab[i].mat!=0)
    			{
    			printf (" nom : %s\t, matricule : %d\t\n", tab[i].nom,tab[i].mat);
    			for (int k=0;k<3;k++)
    			printf (" cotes %d : %3.1f\t",k+1,tab[i].cote[k]);
    			printf ("\n");
    			getch();i++;
    			}
    		else i++;
    		}
    	}
    	fclose(entree);
    }
     getch();
     
     
    /*	if ( entree )  puts (" fichier ouvert avec succes !\n");
    	else 	       puts (" probleme lors de l'ouverture du fichier \n");
    	getch();*/
    }
    //****************************************************************
    void save (etu *tab )
    { //  struct  etu 	p;
    //FILE *entree;
    entree = fopen ("c:\\marc","rb+");
    /*if (entree)
    	printf  (" fichier ouvert\n ");
    else
    	printf (" erreur d'ouverture de fichier\n");
     */
    //strcpy( p.nom, nom);p.cote[0]=c1;p.cote[1]=c2;p.cote[2]=c3;p.mat=matri;
    fwrite (&tab, sizeof (tab), 1,entree);
    fclose(entree);
     
    }
     
    //*****************************************************************
     
    void supprime (int )
    {
    	int t=0,mt;
    	int trouver=0;
    	char	m[5];
    clrscr();
    puts("__________suppression d'un etudiant__________\n");
    printf (" entrez le matricule de l'etudiat a supprimer :\n");
    	gets(m);  mt=lire_int(m);
    while (tab[i].mat!=mt)
    {
    	t++; i++;trouver=0;
    }
    	if (tab[i].mat==mt) 	trouver=1;
    for (i=t;i<maxetu;i++)
    	{
    	 tab[i].mat=tab[i+1].mat;
    	 strcpy (tab[i].nom, tab[i+1].nom);
    	 for (int k=0;k<3;k++)
    	 {
    		tab[i].cote[k]=tab[i+1].cote[k];
    	 }
    	}
    	if (trouver == 0) puts ("etudiant pas dans le fichier \n");
    	else 		  puts (" etudiant supprim‚ ");
    }
    //*****************************************************************
    /*
    etu rech_nom (etu *tab)
    {
    }
     
    //*****************************************************************
    etu rech_mat(etu *tab)
    {         ;
    }
    //*****************************************************************
    void menu_recherche( etu *tab)
    {
    	char 	ch;
     
    clrscr();
    puts ("__________menu de recherche__________\n");
    puts (" 	recherche (N)ominative\n");
    puts (" 	recherche par (M)atricule \n");
    puts ("_____________________________________\n");
    puts (" 	entrez votre choix :\n");
    	ch=getchar ();
    	ch=toupper(ch);
    switch(ch)
    {
    	case 'M' : rech_mat(tab) ; break;
    	case 'N' : rech_nom(tab) ; break;
    }
    } */
    //*******************************************************************
    void menu_fichier()
    {
    	char	mfc;
    clrscr();
    puts ("__________menu fichier__________________________\n");
    puts ("________________________________________________\n");
    puts ("\n");
    puts (" 	(O)uverture du fichier\n");
    puts ("		(S)auvegarde du fichier( format binaire)\n");
    puts ("\n");
    puts ("________________________________________________\n");
    puts (" 	entrez votre choix\n");
    	fflush(stdin);
    	mfc = getchar();
    	mfc = toupper(mfc);
    		       char c[20];
    		       int d,e,f,g;
    switch (mfc)
    {
    	case 'O' : ouverture();
    	case 'S' : save(tab);
    }
    }
    //*****************************************************************
    void menu_etu()
    {
    	int 	matr;
    	char 	c=0;
     
    clrscr();
       while (c!='Q')
     
      { clrscr();
      fflush(stdin);
    puts ("==========menu principale==========\n");
    puts ("___________________________________\n");
    puts (" (E)ncoder \n");
    puts (" (A)fficher \n");
    puts (" (S)upprimer un etudiant \n");
    puts (" (O)ption fichier \n");
    puts (" Entrez (Q) pour sortir \n");
    puts (" menu (R)echerche \n");
    puts ("___________________________________\n");
    puts (" \n");
    puts (" Entrez votre choix : \n");
     
     
    	c=toupper(getch ());
    switch (c)
    {
    	case 'E' : rajoute (  tab);break;
    	case 'A' : afficher (tab);break;
    	case 'O' : menu_fichier();break;
    	case 'S' : supprime (matr);break;
         //	case 'R' : menu_recherche(tab);break;
        //	case 'Q' : printf (" fin du programme");break;
    }
     
    } printf (" fin du programme \n");
     
    getch();
    }
     
    //***************************************************************
     
    void main ()
    {
    clrscr();
    //menu_etu(tab);
    //cha=getchar();
    //while  (cha !='Q');
    	 menu_etu ();
     
     
     
    }
    voila si quelqu'un pouvait me dire quoi ca serait sympa
    merci d'avance
    marc

  2. #2
    Expert éminent sénior
    Avatar de Skyounet
    Homme Profil pro
    Software Engineer
    Inscrit en
    Mars 2005
    Messages
    6 380
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

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

    Informations forums :
    Inscription : Mars 2005
    Messages : 6 380
    Points : 13 380
    Points
    13 380
    Par défaut
    Quelle est la fonction qui ne fonctionne pas au juste, parce que la en fait c'est un peu le bordel (indentation, commentaire) et le code est un peu long quand meme

    Juste une remarque :
    Ca ne fonctionne que sous Windows (fflush est destiné pour les flux sortants)
    Introduction à Silverlight 4 (new) ; Localisation d'une application Silverlight (new) ;
    Mon espace perso[/B]

    La connaissance s’acquiert par l’expérience, tout le reste n’est que de l’information. Albert Einstein[/SIZE]

  3. #3
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Points : 26
    Points
    26
    Par défaut
    j'ai un problèmedans le charger fichier ou le save

  4. #4
    Membre éprouvé
    Profil pro
    Eleveur de cornichons
    Inscrit en
    Juin 2002
    Messages
    1 074
    Détails du profil
    Informations personnelles :
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Eleveur de cornichons
    Secteur : Finance

    Informations forums :
    Inscription : Juin 2002
    Messages : 1 074
    Points : 1 166
    Points
    1 166
    Par défaut
    Y'a un truc bizarre dans ton code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    fwrite (&tab, sizeof (tab), 1,entree);
    Pourquoi mets-tu un '&' ? "tab" est déjà un pointeur.

    Nas'

  5. #5
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Points : 26
    Points
    26
    Par défaut
    même en retirant le & ca ne change rien quand j'essai de rouvrir le fichier après fermeture du programme plus rien dans le fichier alors qu'il est bien créé
    merci

  6. #6
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut Re: [debutant]probleme de sauvetage en fichier binaire
    Citation Envoyé par marc_dd
    bonjour j'ai fait un petit programme avec sauvetage au format binaire mais voila quand je sauve mon fichier il le crée mais ne copie rien dedans voici mon code
    <...>
    Ne compile pas.
    Vérifie que ton compilateur est bien C et non C++. Par exemple, l'extension du fichier doit être .c et non .C ni .cpp...
    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
     
    main.c: In function `lire_mat':
    main.c:53: warning: unused variable `matt'
    main.c: In function `lire_cotes':
    main.c:81: warning: empty body in an else-statement
    main.c: At top level:
    main.c:86: error: syntax error before '*' token
    main.c: In function `init':
    main.c:90: error: 'for' loop initial declaration used outside C99 mode
    main.c: At top level:
    main.c:97: error: syntax error before '*' token
    main.c: In function `rajoute':
    main.c:98: warning: implicit declaration of function `clrscr'
    main.c:99: warning: unused variable `m'
    main.c:100: warning: unused variable `matric'
    main.c:100: warning: unused variable `cot'
    main.c:101: warning: unused variable `b'
    main.c:101: warning: unused variable `c'
    main.c: At top level:
    main.c:139: error: syntax error before '*' token
    main.c: In function `afficher':
    main.c:144: error: 'for' loop initial declaration used outside C99 mode
    main.c: In function `ouverture':
    main.c:153: error: `etu' undeclared (first use in this function)
    main.c:153: error: (Each undeclared identifier is reported only once
    main.c:153: error: for each function it appears in.)
    main.c:153: error: syntax error before "tab1"
    main.c:156: error: 'for' loop initial declaration used outside C99 mode
    main.c:158: error: `tab1' undeclared (first use in this function)
    main.c:159: warning: null argument where non-null required (arg 2)
    main.c:177: error: 'for' loop initial declaration used outside C99 mode
    main.c: At top level:
    main.c:195: error: syntax error before '*' token
    main.c: In function `supprime':
    main.c:212: error: parameter name omitted
    main.c:230: error: 'for' loop initial declaration used outside C99 mode
    main.c:244:2: warning: "/*" within comment
    main.c:248:2: warning: "/*" within comment
    main.c: In function `menu_fichier':
    main.c:283: warning: unused variable `c'
    main.c:284: warning: unused variable `d'
    main.c:284: warning: unused variable `e'
    main.c:284: warning: unused variable `f'
    main.c:284: warning: unused variable `g'
    main() retourne int. Toujours.
    gets() est un bug qu'il ne faut pas utiliser.

    http://emmanuel-delahaye.developpez....tes.htm#saisie
    http://emmanuel-delahaye.developpez....s.htm#fichiers

    Il y a un problème avec la globale i.
    • Elle est masquée (shadowed) par les locales i du même nom
    • Parfois elle n'est pas initialisée.

    Bref, comme souvent avec les globales, sont utilisation n'est pas claire. Je suggerre de la passer en locale exclusivement.

    Ceci est gravement faux :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    void save (struct etu *tab )
    {
    <...>
    fwrite (&tab, sizeof (tab), 1,entree);
    Ca veut dire

    enregistrer le contenu d'un pointeur, soit quelques bytes qui ne représentent rien un fois le programme terminé. LEs données ne sont pas enregistées. Ce qu'il faut faire, c'est ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    fwrite (tab, sizeof *tab, 1,entree);
    On passe l'adresse du bloc (le contenu de tab) et sa taille.

    Manque des breaks dans des 'switch-case'
    Pas de Wi-Fi à la maison : CPL

  7. #7
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Points : 26
    Points
    26
    Par défaut
    je code sous borland C en .cpp en fait désolé

  8. #8
    Expert éminent sénior
    Avatar de Emmanuel Delahaye
    Profil pro
    Retraité
    Inscrit en
    Décembre 2003
    Messages
    14 512
    Détails du profil
    Informations personnelles :
    Âge : 67
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Décembre 2003
    Messages : 14 512
    Points : 20 985
    Points
    20 985
    Par défaut
    Citation Envoyé par marc_dd
    je code sous borland C en .cpp en fait désolé
    Alors renomme en .c et corrige ton code... (manque struct etc.)
    Pas de Wi-Fi à la maison : CPL

  9. #9
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Points : 26
    Points
    26
    Par défaut
    voila le code en .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
    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
     
    #include <conio.h>
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #define maxetu 25
    #define maxcotes 3
     
    struct etu
    {
           int 	mat;
           char 	nom[20];
           float 	cote[maxcotes];
    }       tab[maxetu]   ;
     
    struct cotes
    {
    	float	c1;
    	float 	c2;
    	float 	c3;
    }   ;
    char	cha='Z';
    int	i;
    //FILE *entree;
    //**************************************************************
    int  lire_float (char nbf[5])
    {
           //	char nbf[5];
    	float nbref;
    	do {
    	gets (nbf);fflush(stdin);
    	nbref = atof (nbf);
    	}
    	while (nbref!=0);
    	return (nbref);
    }
    //**************************************************************
    int lire_int(char nbi[5])
    {
         //	char 	nbi[5];
    	int 	nbrei;
    	do {      fflush(stdin);
    	gets(nbi);
    	nbrei= atoi (nbi);
    	}
    	while (nbrei!=0);
    	return (nbrei);
    }
    //**************************************************************
     
    int lire_mat ( int  m)
    { char 	matt[5];int trouve =0;
    /*
    for (i=0;i<maxetu ;i++)
    	{if ( m == tab[i].mat)
    	       {
    		printf (" matricule deja utilise \n");
    		printf (" entrez un nouveau matricule : \n");
    		fflush(stdin);
    		gets(matt);tab[i].mat=lire_int(matt);m=tab[i].mat;
    	       }
    	}    return (m);
           */
    	for (i=0;i<maxetu;i++)
    	{	if (m==tab[i].mat) trouve =1;
    		else trouve = 0;
    	}
    if (trouve == 0) return 1;
    else return 2;
        //		scanf (" %d" , &tab[i].mat );
    }
     
    //**************************************************************
     
    void lire_cotes ( float c)
    {
    if ((c<0)||(c>20))
     {	printf (" entrez autre cotes :");
    	scanf (" %f", &c);}
    	else ;
    }
     
    //*************************************************************
     
    void init ()    // ou tab[]
    {
    for (i=0;i<25;i++)
    	{strcpy ("null",tab[i].nom) ;
    	 for (int j=0;j<3;j++)
    	 tab[i].cote[j]=0.0;
    	}
    }
     
    //*************************************************************
     
    void rajoute ( )//etu *tab)
    {               clrscr();
    	int 	m;
    	char 	matric[5], cot [5];
    	char 	a[3],b,c;
    	int 	j,k,l;
    	int 	tmp ;
    fflush(stdin);
    	printf (" entrez un matricule 0 pour sortir :\n");
    	gets (a);
    while (a[0]!='0')
    {
    	tab[i].mat =atoi(a); k=i;
    	tmp= atoi(a);
    	for  (l=0;l<maxetu && l!=k;l++)
    		{ if (tab[l].mat==tmp) {
    				      printf ("autre matricule :\n");
    				      gets (a);
    				      tab[i].mat= atoi (a);
    		}                     }
     
     
     printf (" entrez le nom de l'etudiant :\n");
     gets (tab[i].nom);
     for (j=0;j<3;j++)
    	{ printf (" entrez la cote nø %d : ",j+1);
    	fflush(stdin);
    	gets (a); tab[i].cote[j]=atoi (a);
    	}
    	i++;
     
     do
     {
     fflush(stdin);
     printf (" entrez le matricule de l'etudiant suivant  0 pour sortir :\n");
     gets (a);
     }
     while ((lire_mat(atoi(a))!=1)&&(atoi(a)!=0));
    }
    }
    //***************************************************************
     
    void afficher ()//etu * tab )
    {                    clrscr();
    for (i=0;i<25 && tab[i].mat!=0;i++)
    {
    	printf ("%d\t %s\t", tab[i].mat, tab[i].nom );
    	for (int j=0;j<maxcotes;j++)
    		printf (" %3.1f ", tab[i].cote[j]);
    puts (" \n");
    }
    getch();
    }
     
    //****************************************************************
    void ouverture()
    {struct	etu	tab1[25];
    FILE 	*entree;
    int i=0;int j=0;
    for ( j=0;j<maxetu;j++);
    	{
    	tab1[j].mat=0;
    	strcpy (tab1[j].nom,NULL);
    	}
    entree = fopen ("c:\\marc", "rb+");
    if( !entree)
           {
    	puts (" erreur d'ouverture de fichier\n");
    	getch();
    	}
    else
    	{
    	if (fread (&tab1[i],sizeof(struct etu),25,entree)>0)
    	{
    		while (i<25 && tab[i].mat!=0 )
     
    		{
    		if (tab[i].mat!=0)
    			{
    			printf (" nom : %s\t, matricule : %d\t\n", tab[i].nom,tab[i].mat);
    			for (int k=0;k<3;k++)
    			printf (" cotes %d : %3.1f\t",k+1,tab[i].cote[k]);
    			printf ("\n");
    			getch();i++;
    			}
    		else i++;
    		}
    	}
    	fclose(entree);
    }
     getch();
    }
    //****************************************************************
    void save ()//(etu *tab )
    { //  struct  etu 	p;
    //FILE *entree;
    entree = fopen ("c:\\marc","rb+");
    /*if (entree)
    	printf  (" fichier ouvert\n ");
    else
    	printf (" erreur d'ouverture de fichier\n");
     */
    //strcpy( p.nom, nom);p.cote[0]=c1;p.cote[1]=c2;p.cote[2]=c3;p.mat=matri;
    fwrite (tab, sizeof (tab), 1,entree);
    fclose(entree);
     
    }
     
    //*****************************************************************
     
    void supprime ()
    {
    	int t=0,mt;
    	int trouver=0;
    	char	m[5];
    clrscr();
    puts("__________suppression d'un etudiant__________\n");
    printf (" entrez le matricule de l'etudiat a supprimer :\n");
    	gets(m);  mt=lire_int(m);
    while (tab[i].mat!=mt)
    {
    	t++; i++;trouver=0;
    }
    	if (tab[i].mat==mt) 	trouver=1;
    for (i=t;i<maxetu;i++)
    	{
    	 tab[i].mat=tab[i+1].mat;
    	 strcpy (tab[i].nom, tab[i+1].nom);
    	 for (int k=0;k<3;k++)
    	 {
    		tab[i].cote[k]=tab[i+1].cote[k];
    	 }
    	}
    	if (trouver == 0) puts ("etudiant pas dans le fichier \n");
    	else 		  puts (" etudiant supprim‚ ");
    }
    //*****************************************************************
    /*
    etu rech_nom (etu *tab)
    {
    }
     
    //*****************************************************************
    etu rech_mat(etu *tab)
    {         ;
    }
    //*****************************************************************
    void menu_recherche( etu *tab)
    {
    	char 	ch;
     
    clrscr();
    puts ("__________menu de recherche__________\n");
    puts (" 	recherche (N)ominative\n");
    puts (" 	recherche par (M)atricule \n");
    puts ("_____________________________________\n");
    puts (" 	entrez votre choix :\n");
    	ch=getchar ();
    	ch=toupper(ch);
    switch(ch)
    {
    	case 'M' : rech_mat(tab) ; break;
    	case 'N' : rech_nom(tab) ; break;
    }
    } */
    //*******************************************************************
    void menu_fichier()
    {
    	char	mfc;
    clrscr();
    puts ("__________menu fichier__________________________\n");
    puts ("________________________________________________\n");
    puts ("\n");
    puts (" 	(O)uverture du fichier\n");
    puts ("		(S)auvegarde du fichier( format binaire)\n");
    puts ("\n");
    puts ("________________________________________________\n");
    puts (" 	entrez votre choix\n");
    	fflush(stdin);
    	mfc = getchar();
    	mfc = toupper(mfc);
    		       char c[20];
    		       int d,e,f,g;
    switch (mfc)
    {
    	case 'O' : ouverture();
    	case 'S' : save();//(tab);
    }
    }
    //*****************************************************************
    void menu_etu()
    {
    	int 	matr;
    	char 	c=0;
     
    clrscr();
       while (c!='Q')
     
      { clrscr();
      fflush(stdin);
    puts ("==========menu principale==========\n");
    puts ("___________________________________\n");
    puts (" (E)ncoder \n");
    puts (" (A)fficher \n");
    puts (" (S)upprimer un etudiant \n");
    puts (" (O)ption fichier \n");
    puts (" Entrez (Q) pour sortir \n");
    puts (" menu (R)echerche \n");
    puts ("___________________________________\n");
    puts (" \n");
    puts (" Entrez votre choix : \n");
     
     
    	c=toupper(getch ());
    switch (c)
    {
    	case 'E' : rajoute (  tab);break;
    	case 'A' : afficher ();break;
    	case 'O' : menu_fichier();break;
    	case 'S' : supprime (matr);break;
         //	case 'R' : menu_recherche(tab);break;
        //	case 'Q' : printf (" fin du programme");break;
    }
     
    } printf (" fin du programme \n");
     
    getch();
    }
     
    //***************************************************************
     
    void main ()
    {
    clrscr();
    //menu_etu(tab);
    //cha=getchar();
    //while  (cha !='Q');
    	 menu_etu ();
     
     
     
    }
    la sauvegarde fonctionne mais
    quand j'essaie d'ouvrir le fichier runtime error segment access violation
    merci de votre compréhension pour mes erreurs
    Marc

  10. #10
    Expert éminent sénior
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Points : 13 926
    Points
    13 926
    Par défaut
    Ce programme ne compile pas : il y a une foultitude d'erreurs. De plus, comme tu as laissé en commentaires tous les essais que tu as fait, des variables ne sont plus définies.
    Mets un peu d'ordre et donne la version opérationnelle actuelle qui cause cette erreur à l'exécution.
    Et enlève cette HORREUR de variable globale i . C'est à vous faire hérisser le poil
    Publication : Concepts en C

    Mon avatar : Glenn Gould

    --------------------------------------------------------------------------
    Une réponse vous a été utile ? Remerciez son auteur en cliquant le pouce vert !

  11. #11
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Points : 26
    Points
    26
    Par défaut
    revoila le code sans variable globale et sans commentaire chez moi ça compile, il y a des warning mais ca compile
    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
     
    #include <conio.h>
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #define maxetu 25
    #define maxcotes 3
     
    struct etu
    {
           int 	mat;
           char 	nom[20];
           float 	cote[maxcotes];
    }       tab[maxetu]   ;
     
    struct cotes
    {
    	float	c1;
    	float 	c2;
    	float 	c3;
    }   ;
     
    //**************************************************************
    int  lire_float (char nbf[5])
    {
        float nbref;
    	do {
    	gets (nbf);fflush(stdin);
    	nbref = atof (nbf);
    	}
    	while (nbref!=0);
    	return (nbref);
    }
    //**************************************************************
    int lire_int(char nbi[5])
    {
    	int 	nbrei;
    	do {      fflush(stdin);
    	gets(nbi);
    	nbrei= atoi (nbi);
    	}
    	while (nbrei!=0);
    	return (nbrei);
    }
    //**************************************************************
     
    int lire_mat ( int  m)
    { char 	matt[5];int trouve =0;int i;
    	for (i=0;i<maxetu;i++)
    	{	if (m==tab[i].mat) trouve =1;
    		else trouve = 0;
    	}
    if (trouve == 0) return 1;
    else return 2;
    }
     
    //**************************************************************
     
    void lire_cotes ( float c)
    {
    if ((c<0)||(c>20))
     {	printf (" entrez autre cotes :");
    	scanf (" %f", &c);}
    	else ;
    }
     
    //*************************************************************
     
    void init ()
    {
    for (int i=0;i<25;i++)
    	{strcpy ("null",tab[i].nom) ;
    	 for (int j=0;j<3;j++)
    	 tab[i].cote[j]=0.0;
    	}
    }
     
    //*************************************************************
     
    void rajoute ( )
    {               clrscr();
    	int 	m;
    	char 	matric[5], cot [5];
    	char 	a[3],b,c;
    	int 	j,k,l;
    	int 	tmp, i =0;
    fflush(stdin);
    	printf (" entrez un matricule 0 pour sortir :\n");
    	gets (a);
    while (a[0]!='0')
    {
    	tab[i].mat =atoi(a); k=i;
    	tmp= atoi(a);
    	for  (l=0;l<maxetu && l!=k;l++)
    		{ if (tab[l].mat==tmp) {
    				      printf ("autre matricule :\n");
    				      gets (a);
    				      tab[i].mat= atoi (a);
    		}                     }
     
     
     printf (" entrez le nom de l'etudiant :\n");
     gets (tab[i].nom);
     for (j=0;j<3;j++)
    	{ printf (" entrez la cote nø %d : ",j+1);
    	fflush(stdin);
    	gets (a); tab[i].cote[j]=atoi (a);
    	}
    	i++;
     
     do
     {
     fflush(stdin);
     printf (" entrez le matricule de l'etudiant suivant  0 pour sortir :\n");
     gets (a);
     }
     while ((lire_mat(atoi(a))!=1)&&(atoi(a)!=0));
    }
    }
    //***************************************************************
     
    void afficher ()
    {                    clrscr();
    for (int i=0;i<25 && tab[i].mat!=0;i++)
    {
    	printf ("%d\t %s\t", tab[i].mat, tab[i].nom );
    	for (int j=0;j<maxcotes;j++)
    		printf (" %3.1f ", tab[i].cote[j]);
    puts (" \n");
    }
    getch();
    }
     
    //****************************************************************
    void ouverture()
    {struct	etu	tab1[25];
    FILE 	*entree;
    int i=0;int j=0;
    for ( j=0;j<maxetu;j++);
    	{
    	tab1[j].mat=0;
    	strcpy (tab1[j].nom,NULL);
    	}
    entree = fopen ("c:\\marc", "rb+");
    if( !entree)
           {
    	puts (" erreur d'ouverture de fichier\n");
    	getch();
    	}
    else
    	{
    	if (fread (&tab1[i],sizeof(struct etu),25,entree)>0)
    	{
    		while (i<25 && tab[i].mat!=0 )
     
    		{
    		if (tab[i].mat!=0)
    			{
    			printf (" nom : %s\t, matricule : %d\t\n", tab[i].nom,tab[i].mat);
    			for (int k=0;k<3;k++)
    			printf (" cotes %d : %3.1f\t",k+1,tab[i].cote[k]);
    			printf ("\n");
    			getch();i++;
    			}
    		else i++;
    		}
    	}
    	fclose(entree);
    }
     getch();
    }
    //****************************************************************
    void save ()
    {
    	FILE *entree;
    entree = fopen ("c:\\marc","rb+");
    fwrite (tab, sizeof (*tab), 1,entree);
    fclose(entree);
     
    }
     
    //*****************************************************************
     
    void supprime ()
    {
    	int t=0,mt,i=0;
    	int trouver=0;
    	char	m[5];
    clrscr();
    puts("__________suppression d'un etudiant__________\n");
    printf (" entrez le matricule de l'etudiat a supprimer :\n");
    	gets(m);  mt=lire_int(m);
    while (tab[i].mat!=mt)
    {
    	t++; i++;trouver=0;
    }
    	if (tab[i].mat==mt) 	trouver=1;
    for (i=t;i<maxetu;i++)
    	{
    	 tab[i].mat=tab[i+1].mat;
    	 strcpy (tab[i].nom, tab[i+1].nom);
    	 for (int k=0;k<3;k++)
    	 {
    		tab[i].cote[k]=tab[i+1].cote[k];
    	 }
    	}
    	if (trouver == 0) puts ("etudiant pas dans le fichier \n");
    	else 		  puts (" etudiant supprim‚ ");
    }
    //*****************************************************************
    /*
    etu rech_nom (etu *tab)
    {
    }
     
    //*****************************************************************
    etu rech_mat(etu *tab)
    {         ;
    }
    //*****************************************************************
    void menu_recherche( etu *tab)
    {
    	char 	ch;
     
    clrscr();
    puts ("__________menu de recherche__________\n");
    puts (" 	recherche (N)ominative\n");
    puts (" 	recherche par (M)atricule \n");
    puts ("_____________________________________\n");
    puts (" 	entrez votre choix :\n");
    	ch=getchar ();
    	ch=toupper(ch);
    switch(ch)
    {
    	case 'M' : rech_mat(tab) ; break;
    	case 'N' : rech_nom(tab) ; break;
    }
    } */
    //*******************************************************************
    void menu_fichier()
    {
    	char	mfc;
    clrscr();
    puts ("__________menu fichier__________________________\n");
    puts ("________________________________________________\n");
    puts ("\n");
    puts (" 	(O)uverture du fichier\n");
    puts ("		(S)auvegarde du fichier( format binaire)\n");
    puts ("\n");
    puts ("________________________________________________\n");
    puts (" 	entrez votre choix\n");
    	fflush(stdin);
    	mfc = getchar();
    	mfc = toupper(mfc);
    		       char c[20];
    		       int d,e,f,g;
    switch (mfc)
    {
    	case 'O' : ouverture();
    	case 'S' : save();
    }
    }
    //*****************************************************************
    void menu_etu()
    {
    	int 	matr=0;
    	char 	c=0;
     
    clrscr();
       while (c!='Q')
     
      { clrscr();
      fflush(stdin);
    puts ("==========menu principale==========\n");
    puts ("___________________________________\n");
    puts (" (E)ncoder \n");
    puts (" (A)fficher \n");
    puts (" (S)upprimer un etudiant \n");
    puts (" (O)ption fichier \n");
    puts (" Entrez (Q) pour sortir \n");
    puts (" menu (R)echerche \n");
    puts ("___________________________________\n");
    puts (" \n");
    puts (" Entrez votre choix : \n");
     
     
    	c=toupper(getch ());
    switch (c)
    {
    	case 'E' : rajoute (  tab);break;
    	case 'A' : afficher ();break;
    	case 'O' : menu_fichier();break;
    	case 'S' : supprime (matr);break;
         //	case 'R' : menu_recherche(tab);break;
        //	case 'Q' : printf (" fin du programme");break;
    }
     
    } printf (" fin du programme \n");
     
    getch();
    }
     
    //***************************************************************
     
    void main ()
    {	char	cha='z';
     
    clrscr();
    	 menu_etu ();
     
     
     
    }
    merci
    Marc

  12. #12
    gl
    gl est déconnecté
    Rédacteur

    Homme Profil pro
    Inscrit en
    Juin 2002
    Messages
    2 165
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Juin 2002
    Messages : 2 165
    Points : 4 637
    Points
    4 637
    Par défaut
    Mis a part, la multitude de warnings qu'il faudrait corriger :

    * tu utilises gets() qui est une fonction dangeureuse, il faut utiliser fgets() qui permet d'indiquer la taille maximale de la saisie.
    * tu utilises fflush(stdin) or fflush n'est defini que sur les flux sortant.
    * tu utilise atoi qui est deprecated (strtol() remplace avantageusement atoi())).
    * tu ouvres les fichiers dans le mode "rb+" (ne serait-ce pas plutot "r+b" que tu voulais mettre) or le mode r+ ne cree pas le fichier si celui-ci n'existe pas (contrairement a w ou a).

  13. #13
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Points : 26
    Points
    26
    Par défaut
    même en a+b toujours la même erreur, de plus pour les warnings j'ai codé tout sous borlandC et il n'y avait rien je viens de commencer aver lcc_win32 je ne vois pas bien ce qu'il veut me dire avec ces warning
    merci de votre compréhension
    Marc

  14. #14
    Rédacteur/Modérateur
    Avatar de Trap D
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    4 942
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 4 942
    Points : 6 498
    Points
    6 498
    Par défaut
    Histoire d'en mettre une couche de plus :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    // un des prototypes de main est int main (void)
    // main DOIT retourner une valeur 0, 1
    int main (void)
    {
      // inutile, tu ne t'en sers pas.   
      //char   cha='z';
     
      clrscr();
        menu_etu ();
     
      return 0;
     
    }
    "La haine seule fait des choix" - Koan Zen
    "Il ne faut pas être meilleur que les autres, il faut être meilleur que soi." Albert Jacquard
    "Ceux qui savent où ils ont posé leur parapluie ne sont pas alcooliques." - pgibonne.
    Faites du Prolog, ça vous changera les idées !
    Ma page Prolog
    Mes codes sources commentés

    Mon avatar : La Madeleine à la veilleuse de Georges de La Tour

  15. #15
    Expert éminent sénior
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Points : 13 926
    Points
    13 926
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    void save () 
    {
       FILE *entree;
    /*   entree = fopen ("c:\\marc","rb+"); */
       entree = fopen ("c:\\marc","wb+");
    Ici en rb+, l'exécution plante si le fichier n'existe pas. Je suppose que c'est le pb que tu signales
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
       fwrite (tab, sizeof (*tab), 1,entree);
       fclose(entree);
    }
    Ceci n'écrit que le premier enregistrement (c'est malin d'appeler ce fichier entree!)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    struct etu 
    {
           int    mat;
           char    nom[20];
           float    cote[maxcotes];
    }       tab[maxetu]   ;
    C'est ce que tu appelles ne plus avoir de global ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    int  lire_float (char nbf[5])
    {
       float nbref;
       do
        {
         .......
        } while (nbref!=0);
       return (nbref);  /*----donc nbref ==0 ---*/
    }
    idem pour lire_int

    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
    void ouverture()
    {
    /*  struct  etu tab1[25];*/
      FILE    *entree;
      int i=0;int j;int k;
      for ( j=0;j<maxetu;j++);
       {
         tab/*1*/[j].mat=0;
         tab/*1*/[j].nom[0] = 0; /* strcpy (tab1[j].nom,NULL);*/
       }
      entree = fopen ("c:\\marc", "rb+");
      if(!entree)
         {
           puts (" erreur d'ouverture de fichier\n");
           getchar(); /*getch();*/
          }
      else
       {
         /*if (fread (&tab1[i],sizeof(struct etu),25,entree)>0) */
         if (fread (tab,sizeof(struct etu),25,entree)>0)
    Que vient faire ce tab1 ????
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    void init ()
    {
     .....
        strcpy ("null",tab[i].nom) ;
    Ceci est totalement incorrect
    - Il y a plein de getch à remplacer par getchar()
    - il y a plein de fflush(stdin) -> voir FAQ
    - La position de la déclaration des variables est souvent incorrecte (tu compile en C ?)
    - etc...
    Bref, il y a du nettoyage à faire. Bon courage
    Publication : Concepts en C

    Mon avatar : Glenn Gould

    --------------------------------------------------------------------------
    Une réponse vous a été utile ? Remerciez son auteur en cliquant le pouce vert !

  16. #16
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Points : 26
    Points
    26
    Par défaut
    quand je sauve il ne garde que le dernier enregistrement introdsuit de plus il me signel un probleme a l'ouverture du fichier , je mets des getch pour rester sur l'écran rien d'autre je ne sais pas si ca change quelque chopse ?
    merci
    Marc

  17. #17
    Rédacteur/Modérateur
    Avatar de Trap D
    Profil pro
    Inscrit en
    Septembre 2003
    Messages
    4 942
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2003
    Messages : 4 942
    Points : 6 498
    Points
    6 498
    Par défaut
    Les getch ne modifient pas l'enregistrements des fichiers.
    Tu m'as l'air de patauger un peu.
    Fais toi une pause, va prendre l'air et reviens avec les idées claires.
    "La haine seule fait des choix" - Koan Zen
    "Il ne faut pas être meilleur que les autres, il faut être meilleur que soi." Albert Jacquard
    "Ceux qui savent où ils ont posé leur parapluie ne sont pas alcooliques." - pgibonne.
    Faites du Prolog, ça vous changera les idées !
    Ma page Prolog
    Mes codes sources commentés

    Mon avatar : La Madeleine à la veilleuse de Georges de La Tour

  18. #18
    Expert éminent sénior
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Points : 13 926
    Points
    13 926
    Par défaut
    il me signel un probleme a l'ouverture du fichier
    Je pense que c'est l'erreur à l'ouverture du fichier que je t'ai signalée
    je mets des getch pour rester sur l'écran rien d'autre je ne sais pas si ca change quelque chopse ?
    getch() n'est pas portable, préfère getchar()
    quand je sauve il ne garde que le dernier enregistrement introdsuit
    Je jette un oeil et je reviens
    Publication : Concepts en C

    Mon avatar : Glenn Gould

    --------------------------------------------------------------------------
    Une réponse vous a été utile ? Remerciez son auteur en cliquant le pouce vert !

  19. #19
    Expert éminent sénior
    Avatar de diogene
    Homme Profil pro
    Enseignant Chercheur
    Inscrit en
    Juin 2005
    Messages
    5 761
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Enseignant Chercheur
    Secteur : Enseignement

    Informations forums :
    Inscription : Juin 2005
    Messages : 5 761
    Points : 13 926
    Points
    13 926
    Par défaut
    Dans une réponse précédente, je te signale que tu n'écris qu'un enregistrement. Si tu écris les 25, ca marche.
    De toute façon, marche ou pas, il y a à mettre tout ça au propre
    Publication : Concepts en C

    Mon avatar : Glenn Gould

    --------------------------------------------------------------------------
    Une réponse vous a été utile ? Remerciez son auteur en cliquant le pouce vert !

  20. #20
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2005
    Messages : 49
    Points : 26
    Points
    26
    Par défaut
    ok merci ca marche en mettant mais toujours la même erreurs quand j'essaie d'ouvrir le fchier
    erreur
    segment violation
    address 0x406c16
    merci d'aider les gens qui débute comme moi mais si tu pouvais me dire ce que tu appel faire du nettoyage ca serait cool
    en tout cas merci

Discussions similaires

  1. probleme téléchargement d'un fichier binaire
    Par airun dans le forum Développement Web en Java
    Réponses: 1
    Dernier message: 16/04/2013, 17h07
  2. probleme de lecture de fichier binaire
    Par sociopath dans le forum Windows
    Réponses: 9
    Dernier message: 14/01/2008, 14h44
  3. [debutant] probleme de fichier
    Par lamoueste dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 22/02/2006, 15h19
  4. Réponses: 11
    Dernier message: 17/11/2005, 17h13
  5. [Debutant] Comment lire la taille d'un fichier binaire ?
    Par Invité dans le forum Entrée/Sortie
    Réponses: 4
    Dernier message: 18/12/2003, 19h20

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