Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!mouse From: mouse@thunder.mcrcim.mcgill.edu (der Mouse) Newsgroups: comp.lang.c Subject: Re: I need help with this structure loop(?) Message-ID: <1991Jun1.205224.27309@thunder.mcrcim.mcgill.edu> Date: 1 Jun 91 20:52:24 GMT References: <789@ra.MsState.Edu> Distribution: usa Organization: McGill Research Centre for Intelligent Machines Lines: 56 In article <789@ra.MsState.Edu>, cee1@ra.MsState.Edu (The Chuckmeister) writes: > [program reading stuff in a loop, first time around works fine, > second time around skips first question] > Oh, back to thinking of what the actual code from my C book .. it > gave the error: 'scanf : floating point formats not linked' and > Abormal Prog. Term. > What the heck did that, I used: > scanf("%f", &libry[count++].value); The problem here is that the DOS compiler you used tries to be smart and not bring in the floating-point support unless you use it. However, you didn't do any floating-point operations the compiler could see; all the floating-point code was hidden in scanf(). A legacy of machines with tiny memories.... I've stripped out most of this code; only the relevant bits remain. > while ( count < MAXNUMBOOKS) > { > gets(inventory[count].author); > gets(inventory[count].title); > scanf("%d", &inventory[count].year); > } The problem is that the scanf is *not* reading the newline at the end of that line. That remains in the stdio buffer for the gets() at the beginning of the next loop to trip over. Generally you don't want to mix line-based I/O (like gets) with format-based I/O (like scanf). You should probably replace the scanf with a call to fgets and then some sort of conversion routine, perhaps a call to sscanf. Which leads me into my next point.... You shouldn't be using gets(). gets() should not exist; please pretend it doesn't. Those who have to maintain your code will thank you. Use fgets() instead. The reason for this is that it has no checking to prevent overrunning the buffer passed to it, and by its very design *cannot* have any such checking. As soon as the day comes when someone types more input than your buffer is prepared to handle, your program will fail in strange and mysterious ways - anything from coming crashing down to giving sutbly wrong answers. gets() was the cause of one of the bugs exploited by the RTM Internet worm of November '88, for precisely the reasons I just outlined. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu