Re: [HELP] Ascii Pfiles and feof

From: Sammy (samedi@ticnet.com)
Date: 01/28/01


On Sun, 28 Jan 2001 21:15:50 -0500, John Sherman wrote:

>   How would I find the EOF with FBFILE in the Ascii Pfile code?
>Has anyone wrote a fbeof function? I tried to find the code for the
>normal feof on the net but couldn't find it. Could someone point in the
>right direction in coding this, or is there already a function included
>in the diskio.c file?

When I wrote the diskio code, I wanted to make file access a little
simpler.  If you look at the code that reads from FBFILE files, I
never use anything like feof().  The functions that read from the
buffers (like fbgetline and fbgetstring) check for an end of file
indication internally by testing for *fbfl-ptr.  Note that diskio
assumes you're always reading from a null-teminated text file.

If you've writtin a new fbget* function, I'd recommend following the
form of fbgetline and return a zero when !*fbfl->ptr.

If you're just using the existing functions to read a new file, you
can test for end of file as you read from it, as load_char does:

while(fbgetline(fl, line)) {
  etc.
}

If you really want to check for EOF manually, you can use this:

int fbeof(FBFILE *fbfl)
{
  if(!*fbfl->ptr)
    return -1;
  else
    return 0;
}

The above will return a non-zero when you've reached the end of file.

Sam

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/03/01 PST