colorful text using printf in C

If you want to print colored text in Windows console, you will have to use Windows API. ANSI.sys support is no longer present in Windows.

In Linux you can still use ANSI escape sequences to color text.


I know that this is incredibly easy to do in C++, but I found this for you to look at in C:

#include <stdio.h>
#include <windows.h>   // WinApi header

int main()
{
  HANDLE  hConsole;
    int k;

  hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

  // you can loop k higher to see more color choices
  for(k = 1; k < 255; k++)
  {
    SetConsoleTextAttribute(hConsole, k);
    printf("%3d  %s\n", k, "I want to be nice today!");
  }

  getchar();  // wait
  return 0;
}

All of the comments will help you to find your way through the code - hope it helps!