Réponse acceptée !
edit : je reposte
désolé j'avais pas fais gaffe
en c c'est a peu pres similaire
typedef struct
{
type1 variable1;
type2 variable2;
...
} enregistrement;
FILE *file;
enregistrement e;
...
/* ouvre le fichier en ecriture binaire */
if( (file = fopen( nom_fichier, "wb" ) ) == NULL )
{
/* erreur, stop */
}
/* ecris l'enregistrement e dans le fichier */
fwrite( &e, sizeof e, 1, file );
/* ferme le flux */
fclose( file );
pour lire :
FILE *file;
enregistrement e;
/* ouverture */
if( (file = fopen( nom_fichier, "wb" ) ) == NULL )
{
/* erreur, stop */
}
/* ecris l'enregistrement e depuis le fichier */
fread( &e, sizeof e, 1, file );
/* ferme le flux */
fclose( file );
la difference mode binaire / texte :
Text files are those where lines are delimited by the special character EOL (End Of Line), and some translations occur when this special character is read or written for that these file can be directly outputed to a console. The End of a text file is defined by the first occurrence of the EOF character.
A binary file is a file where each byte is read or written as a character, no translations occur, and the End of a binary file matches with the physical End of the File.
la liste des modes d'ouvertures ici
[ Lien ]toutes la doc sur les i/o en c ici
[ Lien ]je precise que c'est un resumé