Structures and file io [Archive] - C Board

PDA

View Full Version : Structures and file io


mungyun
05-18-2002, 01:25 PM
ok, i am trying to figure out how to use structs with file i/o. i am not quite sure if i am going in the right direction. i am writing a program that records any user defined files, their modify time, access time, and size. i decided to use a struct like:

typedef struct FRec //Do i even need typedef?
{
char *iofilename;
char *ioaccesstime;
char *iomodsize;
char *iosize;
}Rec1;

i can already get the info into the struct but i am having trouble writing it to a file. also reading from a file. my file format consists of:

filename
access time
modify time
size
...
could someone help a downed C programmer?
-mung

Salem
05-18-2002, 02:48 PM
Like so

fprintf( fp, "%s\n", Rec1.iofilename );


Same sort of idea if you're using binary files and fwrite - you have to write what each pointer points to, not the pointer itself.