Skip to content

Instantly share code, notes, and snippets.

@tim37021
Last active December 16, 2016 06:40
Show Gist options
  • Save tim37021/2a745e687d26be4bbf02f1a4f7804922 to your computer and use it in GitHub Desktop.
Save tim37021/2a745e687d26be4bbf02f1a4f7804922 to your computer and use it in GitHub Desktop.
#include <stdio.h>
/* reference: http://misc.flogisoft.com/bash/tip_colors_and_formatting */
#define GRAY "\e[90m"
#define RED "\e[91m"
#define GREEN "\e[92m"
#define DEFAULT "\e[39m"
const int num_colors = 3;
const char *colors[] = {GRAY, RED, GREEN};
int print_str(const char *str)
{
for(int i=0; str[i]!='\0'; i++) {
printf("%s", colors[i%num_colors]);
putchar(str[i]);
}
}
int main(int argc, char *argv[])
{
print_str("Hello, world\n");
printf(DEFAULT);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment