Consider the structure.
Code: Select all
struct recs {
int no;
char *name;
}r;
Any help greatly appreciated.
Code: Select all
struct recs {
int no;
char *name;
}r;
Code: Select all
// error checking omitted due to laziness
// C++: tell it to write itself :)
struct recs{
int no;
char *name;
void fwrite(FILE * f){
::fwrite(&no,sizeof(no),1,f);
::fwrite(name,strlen(name)+1,1,f);
// assuming you want to write the terminating zero as well
}
};
// or, if you're doing Plain C :-\
void recs_fwrite(recs * p, FILE * f){
fwrite(&p->no,sizeof(p->no),1,f);
fwrite(p->name,strlen(p->name)+1,1,f);
// assuming you want to write the terminating zero as well
}