Click here to Skip to main content
15,902,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C
#include
void main()
{
	printf("Hello C");
	getch();                          //Here getch() is used like this
}


C
#include
#include
void PrintMessage(void)
{
	printf("Hello C");
}

int main()
{
	PrintMessage();
	_getch();                        // here getchch() is used like this
}

I am executing it in Microsoft Visual studio 2017. Can you please explain to me this change that is required by the compiler in executing the command "getch()".

What I have tried:

Output is coming for both the programs. But since i am in beginners stage, i need to know about this change in one command.
Posted
Updated 25-Oct-18 3:12am
v2

You'll need this at the top of your file:
C
#include <conio.h>
(The file name of the one #include in your code seems to have disappeared but because of the printf I assume that one is stdio.h so you won't have conio.h already).
 
Share this answer
 
Nothing to do with Visual Studio, getch and _getch are both C library calls. The second version is the preferred one in the latest versions of the C runtime libraries; see _getch, _getwch | Microsoft Docs[^].
 
Share this answer
 
Yes, thanks for the answer Richard. I also did some research on this and found out that by writing " #define _CRT_SECURE_NO_WARNINGS " on top of the headers, it removes such errors in the programs.
 
Share this answer
 
#include "pch.h"
#include <iostream>
#define getch() _getch()

int main()
{
printf("Hello C");
getch();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900