Welcome to DaniWeb. Please don't hijack someone's thread to ask your question. Giving you a freebe this time because this is your first post :)
You probably need to create another thread for that timer to run in so that it will execute independently of the scanf() function. Exactly how to do that will depend on the operating system and possibly the compiler you are using.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
The way to do it in Turbo C is to use the functions kbhit() and getch() . You will not be using thescan functions because they will stop the program.
Anyway, you should never use the scanf() to read a string. Here's why . It would be useful to read the entire series on the function so you can head off any problems now before using scanf() drives you crazy.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Use it something like this:
char buffer[255] = {0};
int count = 0;
while( kbhit() )
{
buffer[count++] = getch();
}
Now put something like that in your code. But that will also capture backspaces so you might need to make the above code a little more intelligent by decrementingcount when the backspace key is hit. Also if the return value of getch() is 0 that means that a special key such as F1, F2 ... F12, was hit and you need to call getch() a second time to get its value.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
thank you.
just a few more questions
My professor taught us to use getch to see the output.
I'm not familiar with using it as a replacement for scan.
So? My mom taught me fire was hot. Then after research I found it can cook food. Do some researchSo here is the question.
getch() just gets 1 character right?
How could i use it to get a string?
would it be like example:
---------------------------
getch(1st letter)
getch(2nd letter)
--------------------------
And just loop it?
Yeah, kinda.And last question. I'm a little confused with kbhit
kbhit() returns true only when a key is pressed
So the program would continue only if the user presses the correct key?
Sorry for a lot of questions. I haven't used kbhit before
So? I repeat -- research. Look it up. Google or programming manual for your compiler.
It's going to take you a very long time to program if you have to ask a forum how something works and wait 12-48 hours for an answer. We can best help you clean up a problem or steer you in the right direction, but to answer questions like these is a waste of your time. Look up what you need. Then ask what you don't understand.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944