define question

D

david

Hi friends, in vt100

Define Key

Set Key Definition <ESC>[{key};"{string}"p

* Associates a string of text to a keyboard key. {key} indicates
the key by its ASCII value in decimal.


I try:

#define setkey() printf("\x1b[65;\"Hi there\"p")

but doesn't work
 
K

Keith Thompson

david said:
Hi friends, in vt100

Define Key

Set Key Definition <ESC>[{key};"{string}"p

* Associates a string of text to a keyboard key. {key} indicates
the key by its ASCII value in decimal.


I try:

#define setkey() printf("\x1b[65;\"Hi there\"p")

but doesn't work

*How* does it not work? Show us a complete program using that
definition, tell us what it did and what you expected it to do, and we
might be able to help.
 
D

david

Sorry,

#include <stdio.h>

/* Macros term */
#define gotoxy(x, y) printf("\x1b[%d;%dH", (y), (x))
#define clearscreen() printf("\x1b[2J")
#define setkey() printf("\x1b[65;\"Hi there\"p")
/* END Macros term */

int main(void)
{
clearscreen();
gotoxy(1, 1);
printf("%s", "1\n2\n3\n4\5\n");
setkey();
putchar(65);
gotoxy(1, 1);
getchar();
/* Press A */

return 0;
}


All other macros works right but setkey() must print <Hi there> when I
press <A> in console if I understand well http://www.termsys.demon.co.uk/vtansi.htm

david said:
Hi friends, in vt100
Define Key
Set Key Definition <ESC>[{key};"{string}"p
    * Associates a string of text to a keyboard key. {key} indicates
the key by its ASCII value in decimal.
#define setkey() printf("\x1b[65;\"Hi there\"p")
but doesn't work

*How* does it not work?  Show us a complete program using that
definition, tell us what it did and what you expected it to do, and we
might be able to help.

--
Keith Thompson (The_Other_Keith) (e-mail address removed)  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
 
J

Jens Thoms Toerring

Hansjoerg Lipp said:
david said:
#define setkey() printf("\x1b[65;\"Hi there\"p") [...]
setkey();

Does
fflush(stdout);
help?

That was also my first idea but that know seems unlikely
since the other escape sequences seem to work without the
fflush()ing stdout. I guess it got something to do with the
terminal emulation the OP is using and then it's not a C
related problem and better asked in e.g. comp.unix.programmer
(with additonal information what the OP actually is using -
a real VT100 or e.g. xterm or some other emulation).

Regards, Jens
 
R

Richard Bos

david said:
#include <stdio.h>

/* Macros term */
#define gotoxy(x, y) printf("\x1b[%d;%dH", (y), (x))
#define clearscreen() printf("\x1b[2J")
#define setkey() printf("\x1b[65;\"Hi there\"p")
/* END Macros term */

int main(void)
{
clearscreen();
gotoxy(1, 1);
printf("%s", "1\n2\n3\n4\5\n");
setkey();
putchar(65);
gotoxy(1, 1);
getchar();
/* Press A */

return 0;
}

All other macros works right but setkey() must print <Hi there> when I
press <A> in console

You're not pressing anything in any console. You're printing a character
to a console. That's output, not input.

Richard
 
K

Keith Thompson

david said:
#include <stdio.h>

/* Macros term */
#define gotoxy(x, y) printf("\x1b[%d;%dH", (y), (x))
#define clearscreen() printf("\x1b[2J")
#define setkey() printf("\x1b[65;\"Hi there\"p")
/* END Macros term */

int main(void)
{
clearscreen();
gotoxy(1, 1);
printf("%s", "1\n2\n3\n4\5\n");
setkey();
putchar(65);
gotoxy(1, 1);
getchar();
/* Press A */

return 0;
}

All other macros works right but setkey() must print <Hi there> when I
press <A> in console

You're not pressing anything in any console. You're printing a character
to a console. That's output, not input.

Well, peharps he's typing 'A' in response to the getchar() call -- but
that happens after the call to setkey(), so it can't affect it anyway.

Incidentally, when I run the program, it does print "Hi there" --
though the 'H' is missing, presumably because of the terminal control
sequences (I'm too lazy to look up what "\x1b[65;" is supposed to do).

But putchar(65) is horribly bad style. Character constants exist for
a reason: if you want to print 'A', just call putchar('A').
 
C

CBFalconer

david said:
#include <stdio.h>

/* Macros term */
#define gotoxy(x, y) printf("\x1b[%d;%dH", (y), (x))
#define clearscreen() printf("\x1b[2J")
#define setkey() printf("\x1b[65;\"Hi there\"p")
/* END Macros term */

Why do you have all those string escape characters ('\') in your
strings? What are \x and \" intended to represent?

Please do not top-post. Your answer belongs after (or intermixed
with) the quoted material to which you reply, after snipping all
irrelevant material. See the following links:

<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html>
<http://www.netmeister.org/news/learn2quote.html>
<http://cfaj.freeshell.org/google/> (taming google)
<http://members.fortunecity.com/nnqweb/> (newusers)
 
B

Ben Bacarisse

CBFalconer said:
david said:
#include <stdio.h>

/* Macros term */
#define gotoxy(x, y) printf("\x1b[%d;%dH", (y), (x))
#define clearscreen() printf("\x1b[2J")
#define setkey() printf("\x1b[65;\"Hi there\"p")
/* END Macros term */

Why do you have all those string escape characters ('\') in your
strings? What are \x and \" intended to represent?

They are intended to represent exactly what the standard says they
represent. What makes you doubt the intent?
 
K

Keith Thompson

CBFalconer said:
david said:
#include <stdio.h>

/* Macros term */
#define gotoxy(x, y) printf("\x1b[%d;%dH", (y), (x))
#define clearscreen() printf("\x1b[2J")
#define setkey() printf("\x1b[65;\"Hi there\"p")
/* END Macros term */

Why do you have all those string escape characters ('\') in your
strings? What are \x and \" intended to represent?
[snip]

The answer to your last question can be found in the C standard.

In a string literal, \x1b is the character whose numeric value is 0x1b
(decimal 27); it happens to be the ASCII escape character. \" is --
well, I'm sure you already know what it is.

The purpose, at least for the first two macros, should be obvious from
the names of the macros.

If you're pretending ignorance as a way to make the point that
non-portable code is off-topic, it's getting old; just say that it's
off-topic.
 
M

Martin Ambuhl

CBFalconer said:
david said:
#include <stdio.h>

/* Macros term */
#define gotoxy(x, y) printf("\x1b[%d;%dH", (y), (x))
#define clearscreen() printf("\x1b[2J")
#define setkey() printf("\x1b[65;\"Hi there\"p")
/* END Macros term */

Why do you have all those string escape characters ('\') in your
strings? What are \x and \" intended to represent?

You know (or should know) perfectly well. If you really don't know that
\x introduces a hexadecimal constant (in this case 0x1B = encoding for
the ASCII ESC character) and \" is the way to put a double-quote
character in a string, there are some C references you should check.
CBFalconer mentions several in his .sig; why don't you check that.
 
D

david

(I'm too lazy to look up what "\x1b[65;" is supposed to do).

Define Key

Set Key Definition <ESC>[{key};"{string}"p

* Associates a string of text to a keyboard key. {key} indicates
the key by its ASCII value in decimal.

<ESC>[{A};"{Hi there}"p
 
J

J. J. Farrell

david said:
Hi friends, in vt100

Define Key

Set Key Definition <ESC>[{key};"{string}"p

* Associates a string of text to a keyboard key. {key} indicates
the key by its ASCII value in decimal.


I try:

#define setkey() printf("\x1b[65;\"Hi there\"p")

but doesn't work

I don't believe that's a VT100 control command. If you're actually using
a VT100 I wouldn't expect it to work. It's more likely that you're using
some sort of emulator which supports Terminal Control Commands based on
the VT100. You need to check the specification of whatever terminal or
emulator you are using to make sure it implements that particular command.
 
R

Richard Bos

Han from China said:
If that isn't a spoof post, I'm dumbfounded.

I don't think it's a spoof at all, and I gast my flabber that you are
even as much as slightly-less-eloquent-founded.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top