
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
---------------------------------------------------------------------