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
| #include <stdio.h>
#include <stdlib.h>
int main (void)
{
FILE * file = NULL;
char * filename = "test-st";
typedef struct
{
int a;
int b;
}
st_;
/* Deux structures pour les tests. */
st_ st1;
st_ st2;
/* Remplissage. */
st1.a = 32;
st1.b = 45;
/* Ecriture dans le fichier. */
file = fopen (filename, "wb");
fwrite (&st1, sizeof (st_), 1, file);
fclose (file);
file = NULL;
/* Lecture du fichier. */
file = fopen (filename, "rb");
fread (&st2, sizeof (st_), 1, file);
fclose (file);
file = NULL;
/* Affichage. */
printf ("st2.a = %d\nst2.b = %d\n\n", st2.a, st2.b);
return EXIT_SUCCESS;
} |
Partager