Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: fread help Message-ID: <1990Feb17.194423.12047@virtech.uucp> Date: 17 Feb 90 19:44:23 GMT References: <9600005@silver> Reply-To: cpcahil@virtech.UUCP (Conor P. Cahill) Organization: Virtual Technologies Inc., Sterling VA Lines: 37 In article <9600005@silver> mitchemt@silver.ucs.indiana.edu writes: >struct e { > char indicator; > char *description; > char *path; > }; >typedef struct e ENTRY; > >When I try to fread, I get the correct value for 'indicator', but junk for the >other two. Is my code wrong or is the file wrong. If it is the file could The problem is that when you write thay structure to the file only the values of the pointers for description and path get written to the file, not the data that the pointers point to. You should not use pointers when reading and writing to a file unless you are guarranteed that only the current run of your program is using said file and that the values that the pointers point to have the appropriate existance scope. What you probably want to do is: struct e { char indicator; char description[size_for_desc]; char path[size_for_path]; }; (where size_for_desc and size_for_path are the appropriate constant values) Then your fread(), fwrites(), etc will work as you want them to -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+