cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/25/02:25:55

From: kezman AT nOsPaMbigfoot DOT com (Kieran Farrell)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: best way to read selected data from a file?
Message-ID: <3813ec95.19322590@news.pasteur.dialix.com.au>
References: <3812949e_2 AT news DOT chariot DOT net DOT au>
X-Newsreader: Forte Free Agent 1.11/32.235
Organization: DIALix Internet Services
Lines: 37
Date: Mon, 25 Oct 1999 05:57:19 GMT
NNTP-Posting-Host: 203.12.3.8
X-Complaints-To: abuse AT telstra DOT net
X-Trace: nsw.nnrp.telstra.net 940831069 203.12.3.8 (Mon, 25 Oct 1999 15:57:49 EST)
NNTP-Posting-Date: Mon, 25 Oct 1999 15:57:49 EST
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I totally confused my lecturer by understanding pointers and
struggling with filestreams, don't be disparraged it's not an easy
concept. Well heres your answer.

There are many ways to do it, however no book I've ever read has given
the answer. This is the way I'd do it.

struct MyStuff
{
    int Number;
};

int ReadLine(struct MyStuff *Meep, FILE *fp, int Line)
{
    struct MyStuff Temp;
    int i = 0, RetVal = -1;

    rewind(fp); // Make sure you know where your file pointer is!!!
    while( i != (Line-1) || !feof(fp)) /* Must not go past EOF */
    {
        fscanf(fp, "%d", &Temp.Number);
        i++;
        if(feof(fp))
        {
            RetVal = 0;
        }
        
    }
    if( RetVal = -1 )
    {
        /* OK you are now at the line you want to read */
        fscanf(fp, "%d", &Meep->Number);
    }
    return RetVal; /* Returns 0 if unsucsesful, otherwise -1 */
}


- Raw text -


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