Newbie - while loop & scanf problems 
Author Message
 Newbie - while loop & scanf problems

I have included a portion of my code below. The problem that is driving me
crazy is that the first time thru the loop everything works fine but the
second time thru the loop the program just goes by the scanf statement. Could
someone please enlighten me as to what I am doing wrong.

Thanks

Robert Sproat



Mon, 21 Dec 1998 03:00:00 GMT  
 Newbie - while loop & scanf problems

: I have included a portion of my code below. The problem that is driving me
: crazy is that the first time thru the loop everything works fine but the
: second time thru the loop the program just goes by the scanf statement. Could
: someone please enlighten me as to what I am doing wrong.

: Thanks

: Robert Sproat

Where is the portion of your code?
Actually it's better to use fgets to read stuff and then disect it with
sscanf. Or if you insist on scanf you could read an int with the following
int num;
scanf("%d%*[^\n]\n",&num);
to read a character
char ch;
scanf("%c%*[^\n]\n",&ch);
this ensures that no garbage is left lying around after calling scanf

--
---------------------------------------------------------------------


Canada

No beast so fierce but knows some touch of pity
But I know none, And therefore am no beast
              Richard III., William Shakespeare
vim : the best editor
ftp.fu-berlin.de/misc/editors/vim/beta-test
---------------------------------------------------------------------



Mon, 21 Dec 1998 03:00:00 GMT  
 Newbie - while loop & scanf problems

Quote:

>I have included a portion of my code below. The problem that is driving me
>crazy is that the first time thru the loop everything works fine but the
>second time thru the loop the program just goes by the scanf statement. Could
>someone please enlighten me as to what I am doing wrong.

Where's the source code?

I can answer your problem if you post the source code next time. :)

Regards Robbie
      _\|/_
       0 0
---ooo-(_)-ooo---



Wed, 27 Jan 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Newbie - scanf and while loop - correction

2. While loop, scanf problem

3. do scanf() while loop problems

4. (Newbie) My Loop Isn't Looping - Aargh!

5. Newbie problem w/ scanf

6. newbie problem with scanf

7. scanf problem (DATA/MEMORY CONCEPT) (newbie)

8. Newbie Array/Scanf Problem

9. Problem with scanf & struct in Turbo C

10. newbie's answer to two nested for loops problem

11. Newbie stumped again, basic loop problem.

12. scanf() && printf() error

 

 
Powered by phpBB® Forum Software