Advertisement
dmilicev

colors_in_c_v1.c

Nov 13th, 2019
220
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     colors_in_c_v1.c
  4.  
  5. COLOR [attr]
  6.  
  7.   attr        Specifies color attribute of console output
  8.  
  9. Color attributes are specified by TWO hex digits -- the first
  10. corresponds to the background; the second the foreground.  Each digit
  11. can be any of the following values:
  12.  
  13.     background      foreground
  14.  
  15.     0 = Black       8 = Gray
  16.     1 = Blue        9 = Light Blue
  17.     2 = Green       A = Light Green
  18.     3 = Aqua        B = Light Aqua
  19.     4 = Red         C = Light Red
  20.     5 = Purple      D = Light Purple
  21.     6 = Yellow      E = Light Yellow
  22.     7 = White       F = Bright White
  23.  
  24. If no argument is given, this command restores the color to what it was
  25. when CMD.EXE started.  This value either comes from the current console
  26. window, the /T command line switch or from the DefaultColor registry
  27. value.
  28.  
  29. The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute
  30. the COLOR command with a foreground and background color that are the
  31. same.
  32.  
  33. Example: "COLOR fc" produces light red on bright white
  34.  
  35.  system("COLOR FC");
  36. foreground
  37. Example: for blue color of letters write
  38.  
  39.  system("COLOR  1");
  40.  
  41. */
  42.  
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45.  
  46. int main (void)
  47. {
  48.     int background, foreground;
  49.     char color[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
  50.                       'A', 'B', 'C', 'D', 'E', 'F'};
  51.     char command[10];
  52.  
  53.     for(background=0; background<16; background++)
  54.         for(foreground=0; foreground<16; foreground++)
  55.         {
  56.             sprintf(command,"COLOR %c%c",color[background],color[foreground]);
  57.             system(command);
  58.             printf ("\n %s ", command);
  59.             printf ("\n");
  60.             _getch();
  61.         }
  62.  
  63.     system("COLOR 07");     // reset colors
  64.  
  65.     return 0;
  66. }
Advertisement
RAW Paste Data Copied
Advertisement