0

A doubt about getch() function

I just have a doubt about the usage of getch(); in a simple program to print a text. When I am giving the code as https://code.sololearn.com/cb3N8vMDnqr4/?ref=app I m not getting o/p in o/p console. And, when I am using a getch(); I am able to see the o/p like in the code https://code.sololearn.com/cbJh6s8ozUNg/?ref=app . Also, when the return type of the main() is int AND only if I use a getch() I am able to see the o/p like in the code https://code.sololearn.com/cKa3zVBSDtXS/?ref=app. Can u help me with this Guys. Thanks in advance

22nd Dec 2018, 8:16 AM
Balamurali Chellam
Balamurali Chellam - avatar
4 Answers
+ 1
use getchar(); instead of getch(); and write printf line after getchar();
22nd Dec 2018, 9:12 AM
Mayank Dhillon
Mayank Dhillon - avatar
+ 1
Mayank Dhillon I tried it, after inputting a character, the control is coming back from o/p console to editor. I am using Turbo C by the way.
22nd Dec 2018, 9:32 AM
Balamurali Chellam
Balamurali Chellam - avatar
+ 1
You want to print the line after entering the character right? #include <stdio.h> int main() { printf("Hi"); getch(); return 0; } I used this one in sololearns compiler and it worked fine for me as intended, can't say about turboC because I mostly use CodeBlocks for C.
22nd Dec 2018, 9:52 AM
Mayank Dhillon
Mayank Dhillon - avatar
0
Mayank Dhillon Yes, I understood it now. Thank u.
22nd Dec 2018, 9:56 AM
Balamurali Chellam
Balamurali Chellam - avatar