[Dev-C++] character buffering with getch() and gets()
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jon K. <rc...@cr...> - 2000-11-13 09:39:09
|
problem 1:
I'm developing a piddly little program from a learning book, and in my
main(), I've got a statement to get the user's choice from a menu that looks
like this:
choice = getche();
it takes the '1' character required and successfully activates a
particular function. Once inside the function, however, I have this input
statement, to prompt for and get some data for the string "title" in a
struct array.
printf( "Book title : " );
gets( catalog[ recordCount ].title );
Simple, right? Nope. The prompt comes up
Book title : 1
the gets() reads the 1 from the getche() up in the main function... I
have tried all sorts of odd things, placing getch()'s and getche()'s
after/before statements to clear the buffer, substituted a scanf( "%s",
foo ) for the gets(). Even tried testing to see if there was something in
the buffer with kbhit(), and that comes up negative. Any idea why this is
happening?
---------------------------------------------------------------------
problem 2:
any idea how to limit an inputted string to 80 characters and still be
able to read spaces? I tried the following in my above program and it
screwed things up FAR worse...
scanf( "%80[^\n]", string );
I assume it didn't work because scanf left the '\n' in the buffer or
something like that...
Any help is greatly appreciated
-- Jon
---------------------------------
|\ |
| \|ightshade -|---
email: nsh...@cr...
website: http://www.crosswinds.net/~nshadez17/
________________________________________________________
1stUp.com - Free the Web
Get your free Internet access at http://www.1stUp.com
|