Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Termination Upon Esc

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.

Name: Anonymous 2008-04-15 21:31

DON'T HELP HIM!!!

Name: Anonymous 2008-04-15 21:33

DON'T HELP HIM

Name: Anonymous 2008-04-15 21:33

DON'T HELP HIM

Name: Anonymous 2008-04-15 21:34

DON'T HELP HIM

Name: Anonymous 2008-04-15 21:51

Ask your users to remap ESC to CTRL-C

Name: Anonymous 2008-04-15 22:12

Just do it in LISP

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.

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.

Name: Anonymous 2008-04-15 23:46

>>1
You can't do it in C. Give up.

Name: Anonymous 2008-04-15 23:51

>>10
He's right, it's NP complete

Name: Anonymous 2008-04-16 1:39

>>8
Dat sum redefinition of backdoor?

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.

Name: Anonymous 2008-04-16 3:28

>>13
YHBT. It's not NP-complete.

Name: Anonymous 2008-04-16 5:01

>>12
RMS Mark Shuttleworth said so!

Name: Anonymous 2008-04-16 5:15

char ch=getch();
if(ch==27)
   exit(1);

should work, i didnt bother trying

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

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.

Name: Anonymous 2008-04-16 7:10

use ncurses

Name: Anonymous 2008-04-16 9:22

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;
}

Name: Anonymous 2008-04-16 9:40

Indent failure.

Name: Anonymous 2008-04-16 9:51

how about inserting something along the lines of:

if(kbhit() && getch()==27)
   exit(1);

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.

Name: Anonymous 2009-08-16 22:44

Lain.

Name: Anonymous 2011-02-03 3:55

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List