// What does Vidar Hokstad mean that for a terminal app, you often // don’t need tools others build? Here’s a colored table of cubes in // 10 lines of code just in terms of fputs and putchar. // #include void sput(const char *s) { fputs(s, stdout); } // Print a space-padded unsigned number in a field of width up to 9. void uput(int width, unsigned n) { n/10 ? uput(width-1, n/10) : width > 0 ? sput(" " + 9 - width) : 0; putchar('0' + n % 10); } int main() { for (int i = 0; i < 20; i++) { uput(2, i); sput("³ = \033[32m"); uput(4, i*i*i); sput("\033[0m\n"); } return 0; }