I\'d like to save a struct in a file. I\'d like to realize a function which makes this work. I tried this code but it didn\'t work.
struct utilisateur //
Just a simple example :)
// your struct
struct Data
{
int first;
double second;
char third[10];
};
Then write the struct!
struct Data data = {22, 4.0, "Hi"};
FILE* output;
output = fopen("Data.dat", "wb");
fwrite(&data, sizeof(data), 1, output);
fclose(output);
Finally read the data from the file you created!
struct Data data;
FILE* input;
input = fopen("Data.dat", "rb");
fread(&data, sizeof(data), 1, input);
// you got the data from the file!
fclose(input);
Binary files are nightmares if not written and read wisely. You have to take care of a lot of things about the architecture where the file was created and where will it be read. Endianess and size of variables are the most important. Also, If you have pointers inside your struct, the pointer that will be written to the file not the actual data where the pointer points to. Sorry, I didn't edit your code because it is full of compilation errors :)
I deleted my first answer because it was so wrong, sorry :)