delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/10/16:50:29

From: "Marp" <Marp AT 0 DOT 0 DOT 0 DOT 0>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Help with EOF
Date: Sat, 10 Jul 1999 15:28:32 -0400
Organization: Netcom
Lines: 44
Message-ID: <7m86t6$4v2@dfw-ixnews11.ix.netcom.com>
References: <37877c8f DOT 2555669 AT news DOT smartnet DOT com DOT sg>
NNTP-Posting-Host: prn-nj1-06.ix.netcom.com
X-NETCOM-Date: Sat Jul 10 2:28:38 PM CDT 1999
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2014.211
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

tripleZ <triplez AT singnet DOT com DOT sg> wrote in message
news:37877c8f DOT 2555669 AT news DOT smartnet DOT com DOT sg...
>
> i've got a problem with EOF.. here's the code
>
> <snip>
>
> file = fopen ("records.txt","r");
You should first make sure file isn't null like this:

if(!file)
{
    perror("records.txt");
    return -1;
}

>  while (!EOF(file))

EOF is not a function, it's a preprocessor #define. Use function feof() like
this:

while(!feof(file))

>  {
>   fscanf(file, "%d %d %d\n", n1, n2, n3);
>   if (n3 == key)
>   {
>    g_class = n1;
>    g_student = n2;
>    fclose(file);
>    return 0;
>   }
>   else
>   {
>    fclose(file);
>    return -1;
>   }
>  }
>
> <snip>
>


- Raw text -


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