Termination Upon Esc
1
Name:
Anonymous
2008-04-15 21:30
#include "iostream"
#include "conio.h"
using namespace std;
void main ()
{
signed int a=0;
do
{
a++;
cout<<a<<endl;
}
while (a>-1);
getch();
}
I want this loop program to terminate upon pressing esc key. How do I do that /prog/? Halp me pls.
2
Name:
Anonymous
2008-04-15 21:31
DON'T HELP HIM!!!
3
Name:
Anonymous
2008-04-15 21:33
DON'T HELP HIM
4
Name:
Anonymous
2008-04-15 21:33
DON'T HELP HIM
5
Name:
Anonymous
2008-04-15 21:34
DON'T HELP HIM
6
Name:
Anonymous
2008-04-15 21:51
Ask your users to remap ESC to CTRL-C
7
Name:
Anonymous
2008-04-15 22:12
Just do it in LISP
8
Name:
Anonymous
2008-04-15 22:29
Unfortunately , conio.h is a header file of a proprietary library for DOS console output , so you can't be free when you use it (you can't study or modify it's code).
Thus, conio library contains a backdoor .
The piece of software in question is non-free , therefore I can't link it with my programs and I can't recommend it to anyone.
9
Name:
Anonymous
2008-04-15 23:13
>>8
I have the source code to Microsoft's Visual Sepples CRT. I believe it comes with the
Visula Studio Standard versions and above.
10
Name:
Anonymous
2008-04-15 23:46
>>1
You can't do it in C. Give up.
11
Name:
Anonymous
2008-04-15 23:51
>>10
He's right, it's NP complete
12
Name:
Anonymous
2008-04-16 1:39
>>8
Dat sum redefinition of backdoor?
13
Name:
Anonymous
2008-04-16 1:40
>>11
FFS, just because it's NP complete doesn't mean it's impossible. It will only be pratcial for small cases (< size 50), but OP's program seems simple enough, so it should work.
14
Name:
Anonymous
2008-04-16 3:28
>>13
YHBT. It's not NP-complete.
15
Name:
Anonymous
2008-04-16 5:01
>>12
RMS Mark Shuttleworth said so!
16
Name:
Anonymous
2008-04-16 5:15
char ch=getch();
if(ch==27)
exit(1);
should work, i didnt bother trying
17
Name:
Anonymous
2008-04-16 5:29
#include<conio.h>
#include<stdio.h>
int main(void){
char ch;
do{
ch = getch();
printf("%c %d\n",ch,ch);
}while(ch!=13);//ends when this key is pressed(enter)
return 0;
}
and run this to get the values of other keyboard keys
18
Name:
Anonymous
2008-04-16 6:38
>>13
It's not NPC, it's
just impossible with C or C++. OP will have to use some external libraries, or OS hacks.
19
Name:
Anonymous
2008-04-16 7:10
use ncurses
20
Name:
Anonymous
2008-04-16 9:22
21
Name:
Anonymous
2008-04-16 9:38
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
static struct termios oldt;
void restore_term() {
tcsetattr(0, TCSANOW, &oldt);
}
int main(void){
struct termios t;
char c;
tcgetattr(0, &oldt);
atexit(restore_term);
t = oldt;
t.c_lflag &= ~ICANON & ~ECHO;
t.c_cc[VMIN] = 1;
t.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &t);
do {
read(0, &c, 1);
printf("%d %c\n", c, c);
} while(c != 27);
return 0;
}
22
Name:
Anonymous
2008-04-16 9:40
Indent failure.
23
Name:
Anonymous
2008-04-16 9:51
how about inserting something along the lines of:
if(kbhit() && getch()==27)
exit(1);
24
Name:
Anonymous
2009-03-06 5:43
For example is stupid cunt in the output of the triangle You also like anal sex you homosexual tramp.
25
Name:
Anonymous
2009-08-16 22:44
Lain.
27
Name:
Anonymous
2011-02-03 3:55