3 Replies - 8859 Views - Last Post: 18 June 2008 - 08:18 AM Rate Topic: -----

#1 Nadia88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-June 08

problem with getch & getche

Post icon  Posted 17 June 2008 - 02:30 AM

i tried to run a few simple & similar programms using "getche"( or "getch")
but they all show the same errors.Here 's one of the codes:



#include <stdio.h>
#define STOP '*'

main()
{

	char ch;
	ch=getch();
	while(ch!=STOP)
	{
		putchar(ch);
		ch=getche();
	}


}





the errors are:
error C2065: 'getch' : undeclared identifier
error C2065: 'getche' : undeclared identifier

what do I do wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: problem with getch & getche

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5392
  • View blog
  • Posts: 27,387
  • Joined: 10-May 07

Re: problem with getch & getche

Posted 17 June 2008 - 02:34 AM

View PostNadia88, on 17 Jun, 2008 - 05:30 AM, said:

error C2065: 'getch' : undeclared identifier
error C2065: 'getche' : undeclared identifier


The reason for these errors is because the functions getch & getche are not ansi standard, so they are not defined in stdio.h. You will either need to include the header files that define the functions, or use standard code.
Was This Post Helpful? 0
  • +
  • -

#3 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 119
  • View blog
  • Posts: 1,565
  • Joined: 25-January 07

Re: problem with getch & getche

Posted 17 June 2008 - 03:01 AM

no2pencil has already told you the reason behind it.

Still if you want to make your code run, add this line to your code #include<conio.h> this is a console input/output header file for DOS shell [assuming that you are working in Microsoft based OS]. Try it and see if it helps you.
Was This Post Helpful? 1
  • +
  • -

#4 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: problem with getch & getche

Posted 18 June 2008 - 08:18 AM

yeah, getch doesn't exactly work in *nix...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1