Printing to same line.
|
|
I have to use enter key for printing a result to a terminal. example> input : 2 3 result : 5 The example’s scenario is the following. First, Inputing 2 and 3 Second, Clicking enter key Finally, 5 is printed. This is so simple. By the way, I have to print the result to same line like the following. - input : 2 3 result : 5 Plz help me. ps : I am using C and working in linux |
|
|
This should work: include <conio>int main() { int x,y; char space, break; printf(”- input : “); x = (int)(_getche() – 48); space = _getche(); if (space != ’ ‘) { printf(”\r\nExpecting space after first summand.\r\n”); return 0; } }
Sorry for the lack for formatting. This is mailer code. IT might not work exactly. |
|
|
OK. I have no idea why it formatted it like that. Are there code flags you can put around code so it formats it properly? |
|
|
Thank you. I got a hint,it is getch() function, to you and I made it. |
|
|
Yep they’re in conio.h use _getch() though, not getch(), for better portability. Also, _getche() grabs the char and echoes it to screen as well, where as _getch() just grabs it with no echo. Glad I could help even though I couldn’t format my code snippet for you! |
