Friday, January 8, 2010

I need help with the scanf function in C programming. I want to print text on the same line after using it.?

Anytime i use the scanf function the program i write automatically moves to the next after executing the scanf line. I'd like to know if theres a way of taking in an integer with scanf and printing text afterwards on the same line. I need help with the scanf function in C programming. I want to print text on the same line after using it.?
The problem lies in the fact that scanf() only has data to read after an Enter has been pressed, which advances the cursor to the next line. You may be able to read character by character by using getch() or getchar().





If you can, because you'll be reading at the character level rather than at the line level, you're going to have to devise another way to digest the input. Accumulating the characters in a buffer and handing it off to sscanf() (Note the different name -- this works on a buffer, not a file) is one way. Due to the lack of an Enter, you may also need a way to detect when the input is done.





Hope that helps.

No comments:

Post a Comment