Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!asuvax!noao!amethyst!raw From: raw@math.arizona.edu (Rich Walters) Newsgroups: comp.lang.c Subject: Re: fread help Message-ID: <1432@amethyst.math.arizona.edu> Date: 19 Feb 90 04:39:25 GMT References: <9600005@silver> <1990Feb17.194423.12047@virtech.uucp> Sender: news@amethyst.math.arizona.edu Organization: Dept. of Math., Univ. of Arizona, Tucson AZ 85721 Lines: 43 In article <1990Feb17.194423.12047@virtech.uucp> cpcahil@virtech.UUCP (Conor P. Cahill) writes: >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. > > >What you probably want to do is: > struct e { > char indicator; > char description[size_for_desc]; > char path[size_for_path]; > }; > >Then your fread(), fwrites(), etc will work as you want them to I don't think that this will work very well either. If the file is less than 1 + size_for_desc + size_for_path then the strings may/will be scrambled. This may be avoided if the strings are padded/truncated to the desired length. The problem is that fread() will end each string with \n instead of \0 so that it is difficult to use them immediately with _any_ C routine that requires a string. Of course the \n can be replace with the \0 needed, but is seems to me to be easier, IMHO, to use fgets/fgetc in the first place. Richard Walter ------------------------------------------------------------------------------- Keep on crunching those numbers -------------------------------------------------------------------------------