I am writing a C++ program where I have to come out of the program when "enter" key is pressed
In C++ program how to use "enter" key to quit program?
This is a simple one. Here's the answer...
main()
{
char ch;
a:ch=getch();
if(ch=='\n')
exit();
else
goto a;
}
You may include the header file stdlib.h as exit function is defined in that file.
Reply:check the key entered
the ascii char representing the enter key is '\r'
then use the exit function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment