2

Below code works in DevC++ with MinGW works flawlessly but Visual Studio 2008 spits this:

error C3861: 'getch': identifier not found . 

What can I do to accept getch() if this is not possible is there an alternative to getch() that I can use to pause the screen?

Code:

#include <stdio.h>
#include <conio.h>

int main(void){

    char str[] = "This is the end";
    printf("%s\n", str);
    getch();   //I tried getchar() also still does not work
    return 0;

}
Lyrk
  • 1,936
  • 4
  • 26
  • 48

2 Answers2

6

use _getch()

e.g.

#define getch() _getch()

sample

#include <stdio.h>
#include <conio.h>

#ifdef _MSC_VER
#define getch() _getch()
#endif

int main(void){

    char str[] = "This is the end";
    printf("%s\n", str);
    getch();
    return 0;

}
BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70
  • Which header should I include for it? – Lyrk May 06 '13 at 19:45
  • @user1939432 `#include `. `getch()` without an underscore is declared there too, at least in newer versions of Visual Studio. – Joachim Isaksson May 06 '13 at 19:46
  • @user1939432 `#include ` . `#define getch() _getch()` is replacing the convenience. – BLUEPIXY May 06 '13 at 19:47
  • I tried it but it gives this error. " error C3861: '_getch': identifier not found" . ıf you have Visual Studio can you please try if it works or not? If it is working in your machine, I will uninstall Visual Studio. It is such a pain for C – Lyrk May 06 '13 at 19:57
  • 1
    @user1939432 see http://msdn.microsoft.com/en-us/library/078sfkak%28v=vs.90%29.aspx work for VS2008, my enviroment VS2010 works. – BLUEPIXY May 06 '13 at 20:01
  • @BLUEPIXY , what is the _getch() ? Why should we define it? – bzal Feb 26 '17 at 11:11
  • @BLUEPIXY , is it something defined for C11 compilers? – bzal Feb 26 '17 at 11:11
  • @bzal [This POSIX function is deprecated beginning in Visual C++ 2005.](https://msdn.microsoft.com/en-us/library/ms235446(vs.90).aspx) – BLUEPIXY Feb 26 '17 at 16:31
  • @bzal _is it something defined for C11 compilers?_ No. It is not a standard function of C. – BLUEPIXY Feb 26 '17 at 16:32
0

You can use as well as

#include<iostream>

    int main()
{

system("pause");
return 0;
}