Home  >  Informatica  >  Corso C Avanzato  >  Colore!

Colore in C

Coloriamo la console in C su Linux e Mac!

Download Slides in formato .pdf

Materiali


Il sorgente del codice mostrato nella slide numero 5 e 6.


Download del codice
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
//foreground
#define F_RED  "\x1b[31m"
#define F_GREEN  "\x1b[32m"
#define F_YELLOW  "\x1b[33m"
#define F_BLUE  "\x1b[34m"
#define F_MAGENTA "\x1b[35m"
#define F_CYAN  "\x1b[36m"
#define F_WHITE  "\x1b[37m"
//background
#define B_RED  "\x1b[41m"
#define B_GREEN  "\x1b[42m"
#define B_YELLOW  "\x1b[43m"
#define B_BLUE  "\x1b[44m"
#define B_MAGENTA "\x1b[45m"
#define B_CYAN  "\x1b[46m"
#define B_WHITE  "\x1b[47m"

#define RESET_COLOR  "\x1b[0m"

char* foreground[] = {F_RED,F_GREEN,F_YELLOW,F_BLUE,F_MAGENTA,F_CYAN,F_WHITE};
char* background[] = {B_RED,B_GREEN,B_YELLOW,B_BLUE,B_MAGENTA,B_CYAN,B_WHITE};

int main ()
{
  printf(F_MAGENTA  B_CYAN  "Console a colori!"  RESET_COLOR "\n");
  printf(F_CYAN  B_WHITE  "Console a colori!"  RESET_COLOR "\n");
  printf(F_WHITE  B_RED  "Console a colori!"  RESET_COLOR "\n");
  printf(F_RED  B_GREEN  "Console a colori!"  RESET_COLOR "\n");
  printf(F_GREEN  B_MAGENTA  "Console a colori!"  RESET_COLOR "\n");
  printf(F_YELLOW  B_BLUE  "Console a colori!"  RESET_COLOR "\n");
  printf(F_BLUE  B_YELLOW  "Console a colori!"  RESET_COLOR "\n");
 
  
printf( "%s %s Prova colori con array!"  RESET_COLOR "\n",foreground[3] , background[4] );
  
  return 0;
}


 

Linguaggio C