Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!lavaca.uh.edu!menudo.uh.edu!nuchat!sugar!peter From: peter@sugar.hackercorp.com (Peter da Silva) Newsgroups: comp.sys.amiga.tech Subject: Re: feof does not work: HELP! Keywords: C trouble Message-ID: <7172@sugar.hackercorp.com> Date: 1 Dec 90 01:22:26 GMT References: <4413@ruuinf.cs.ruu.nl> Reply-To: peter@sugar.hackercorp.com (Peter da Silva) Organization: Sugar Land Unix - Houston Lines: 15 In article <4413@ruuinf.cs.ruu.nl> ptavoly@cs.ruu.nl (Peter Tavoly) writes: > 40 while (!feof(in)) /* <- this is where the trouble starts :( */ > 41 { > 42 printf ("%2d. ",y+1); /* print line number */ > 43 while ((ch=fgetc (in))!='@') /* read until separator encountered */ ^^^^^ What happens if you hit EOF here? After reading the final line you're going to sit in an infinite loop comparing EOF with '@'. The simplest fix is to insert "!feof(in) && " before "(ch=fgetc", but I'd read the whole line into memory and manipulate it there. Not quite as efficient, maybe, but I/O time is likely to dominate in this application. -- Peter da Silva. `-_-' .