How do I send escape sequences to control a terminal or other device?

Q

How do I send escape sequences to control a terminal or other device?

✍: Guest

A

If you can figure out how to send characters to the device at all , it's easy enough to send escape sequences. In ASCII, the ESC code is 033 (27 decimal), so code like
fprintf(ofd, "\033[J");
sends the sequence ESC [ J .
Some programmers prefer to parameterize the ESC code, like this:
#define ESC 033
fprintf(ofd, "%c[J", ESC);

2015-04-20, 1314👍, 0💬