PDA

Click to See Complete Forum and Search --> : Input from Keyboard


squirrelly1
Dec 9th, 2002, 02:34 PM
When I use this code:


printf("Do you want to enter another student? [y/n]");
scanf("%c",&v);
if(v=='y'){
goto EnterStudent;
}


It doesn't allow me to input data from the keyboard but instead it move right to the prompt... All of the files I have opened are closed, so I don't know where it is pulling the data from....

Is there any way to ensure that the data is inputted from the keyboard?

thnx,
squirrelly1

jim mcnamara
Dec 9th, 2002, 04:06 PM
Look into gets() and getc() for direct keyborad input - gets() waits for a return key press before returning data to the program, getc() returns each keystroke.

C++ has iostream which gives you .getline

CornedBee
Dec 10th, 2002, 09:34 AM
It probably reads an old newline still in the pipeline. You could try adding this before reading:
fseek(stdin, 0, SEEK_END);