Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!rpi!uwm.edu!ux1.cso.uiuc.edu!osiris.cso.uiuc.edu!gordon From: gordon@osiris.cso.uiuc.edu (John Gordon) Newsgroups: comp.lang.c Subject: Re: problems with scanf() and gets() Message-ID: <1991Jun6.182118.16211@ux1.cso.uiuc.edu> Date: 6 Jun 91 18:21:18 GMT References: <2759@apss.apss.ab.ca> Sender: usenet@ux1.cso.uiuc.edu (News) Distribution: comp Organization: University of Illinois at Urbana Lines: 20 jhp@apss.ab.ca (Herbert Presley) writes: >scanf() and gets() will not accept keyboard input in the same program if >scanf() is used first. I am using scanf() to accept an integer from the >keyboard and gets() to accept a string. Because scanf() aborts input at >the first whitespace, you cannot enter a sentence string (or, is this something >I am doing wrong because of my inexperience)? So in instances where you are >attempting to enter a formatted integer variable and a string in the same >program, I find that using scanf() first makes gets() skip the wait for >keyboard input. Here is your problem: scanf() leaves a carriage return hanging in the input buffer. Since gets() ends on a carriage return, it picks this up immediately and quits. My solution is to do a getchar() right after a scanf() and suck up the floating carriage return. --- John Gordon Internet: gordon@osiris.cso.uiuc.edu #include gordon@cerl.cecer.army.mil #include