What does printf("\033c" ) mean?
c, console, printf, terminal, unix
Solution
In C numbers starting with a leading zero are octal numbers. Numbers in base 8.
What it does is print the character represented by octal number `33` followed by a `'c'`.
In ASCII encoding the octal number `33` is the `ESC` (escape) character, which is a common prefix for terminal control sequences.
With that knowledge searching for terminal control sequences we can find e.g. this VT100 control sequence reference (VT100 was an old "dumb" terminal, and is emulated by most modern terminal programs). Using the VT100 reference we find `<ESC>c` in the terminal setup section, where it's documented as
Reset Device `<ESC>c`
Reset all terminal settings to default.
The `ESC` character could also be printed using `"\x1b"` (still assuming ASCII encoding). There is no way to use decimal numbers in constant string literals, only octal and hexadecimal.
However (as noted by the comment by chux) the sequence `"\x1bc"` will not do the same as `"\033c"`. That's because `0x1bc` is a valid hexadecimal number, and the compiler is greedy when it parses such sequences. It will print the character represented by the value `0x1bc` instead, and I have no idea what it might be (depends on locale and terminal settings I suppose, might be printed as a Unicode character).
Problem
I was looking for a way to "reset" my Unix terminal window after closing my program, and stumbled upon `printf("\033c" );` which works perfectly, but I just can't understand it. I went to `man console_codes` and since I'm somewhat inexperienced with Unix c programming, it wasn't very helpful. Could someone explain `printf("\033c" );`?