Introduction to Programming

Colors


#include <stdio.h>

void doColor(int c)
{
    if (c >= 0 && c <= 8)
        printf("\033[3%dm", c);
}

void undoColor()
{
    printf("\033[m");
}

int main(int argc, char *argv[])
{
    int i;

    for (i=0; i<8; i++)
    {
        printf("Hello, ");
        doColor(i);
        printf("this is color %d!\n", i);
        undoColor();
    }

    return 0;
}

Next: Adventure

Previous: Guessing Game Challenge


Introduction to Programming

Home