www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/23/02:50:00

Date: Thu, 23 Jul 1998 09:49:51 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Jim Barlow <Jim_Barlow AT bc DOT sympatico DOT ca>
cc: djgpp AT delorie DOT com
Subject: Re: File I/O problem (newbie)
In-Reply-To: <35B63092.87C8C431@bc.sympatico.ca>
Message-ID: <Pine.SUN.3.91.980723094931.14884G-100000@is>
MIME-Version: 1.0

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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019