Interview Questions

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

C Interview Questions and Answers


(Continued from previous question...)

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

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

(Continued on next question...)

Other Interview Questions