From: "Marp" 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 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 > > > > 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; > } > } > > >