=== Scrittura ===
- Codice:
typedef struct{
char *name;
char *surname;
int age;
}Person;
int main()
{
FILE * f = fopen("file","wb");
if(f == NULL ) return -1;
Person *io = malloc(sizeof(Person));
if ( io == NULL ) return -1;
io->name = "Andrea";
io->surname = "Rossi";
io->age=23;
fwrite( io, sizeof(Person), 1, f );
fclose(f);
return 0;
}
===Lettura===
- Codice:
typedef struct{
char *name;
char *surname;
int age;
}Person;
int main()
{
Person *io = malloc(sizeof(Person));
FILE *f = fopen("file","rb");
if( f == NULL ) return -1;
rewind(f);
fread(io, sizeof(Person), 1, f);
printf("Name:%s", io->name);
fclose(f);
return 0;
}
Mi stampa Name:Name%s.
Potete darci un'occhiatina gentilmente?
Grazie e buona giornata.