Skip to content

Instantly share code, notes, and snippets.

@montyanderson
Created March 12, 2015 20:06
Show Gist options
  • Save montyanderson/90f58e4a8a4a14c299ed to your computer and use it in GitHub Desktop.
Save montyanderson/90f58e4a8a4a14c299ed to your computer and use it in GitHub Desktop.
An endless C program showing different terminal colors.
#include <stdio.h>
#define KRED "\x1B[31m"
#define KGRN "\x1B[32m"
#define KYEL "\x1B[33m"
#define KBLU "\x1B[34m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
int main(void) {
while(1 > 0) {
switch(rand() % 7) {
case 0:
printf(KRED "red");
break;
case 1:
printf(KGRN "green");
break;
case 2:
printf(KYEL "yellow");
break;
case 3:
printf(KBLU "blue");
break;
case 4:
printf(KMAG "magenta");
break;
case 5:
printf(KCYN "cyan");
break;
case 6:
printf(KWHT "white");
break;
}
printf(" ");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment