Date: Thu, 23 Jul 1998 09:49:51 +0300 (IDT) From: Eli Zaretskii To: Jim Barlow cc: djgpp AT delorie DOT com Subject: Re: File I/O problem (newbie) In-Reply-To: <35B63092.87C8C431@bc.sympatico.ca> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Wed, 22 Jul 1998, Jim Barlow wrote: > I'm trying to read a binary file that contains some null-terminated strings. > The program is designed to edit these strings. Here's my code: No offence, but the code you posted is such an incredible hodgepodge of errors and possible typos that it's almost impossible to give you any useful advice. Please try in the future to do a better job when posting code; at least make sure it compiles. > OFF_LIST *cur; `OFF_LIST' is not declared anywhere, so it's impossible to understand what it stands for. > filesize = getfsize (fp); > buffer = offset = (char *)safemalloc (sizeof(char) * filesize); > > fread (buffer, sizeof(char), filesize, fp); Your `getfsize' function seeks to the end of the file, and leaves the stream pointer there. Then you are reading from the same stream. What do you expect to get except an immediate EOF? > cur = &first; // point to the first item in the list `first' is not declared anywhere, so I don't know what does this do. > while (offset = (char *)memchr (buffer, (int)"myst", filesize)) // returns NULL on failure `memchr' needs a character as its second argument, but you pass it a pointer to the string "myst", which will never do what you want. If you want to find the string "myst" inside the buffer that was read from the file, you need to say this: while (offset = (char *)memchr (buffer, (int)"myst"[0], filesize)) > For some reason, this function always returns F_NOWAVS even if the > file consists completely of "mystringmystringmystringmysting...." There's no F_NOWAVS in all the code you posted, so I can't even understand your problem clearly.