Skip to content

Instantly share code, notes, and snippets.

@msetzu
Created February 9, 2019 09:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msetzu/22a2717498e98834c35e235b7398edc3 to your computer and use it in GitHub Desktop.
Save msetzu/22a2717498e98834c35e235b7398edc3 to your computer and use it in GitHub Desktop.
Colored printf in C
#include <stdio.h>
/* Colori definiti secondo lo standard ANSI/C */
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
int main() {
printf(ANSI_COLOR_RED "Stringa rossa..\n");
printf("Stringa ancora rossa.." ANSI_COLOR_RESET "\n");
printf("Colore di default!\n\n");
printf(ANSI_COLOR_RED "Stringa rossa.." ANSI_COLOR_RESET "Poi di default..." ANSI_COLOR_BLUE "Poi blu.\n" ANSI_COLOR_RESET);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment