Last active
December 16, 2016 06:40
-
-
Save tim37021/2a745e687d26be4bbf02f1a4f7804922 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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