Thread: Newbie Question

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    3

    Newbie Question

    Hi
    I started to learn C a week ago and I did a pretty good Tutorial but I do not know how to write colorful text, fat, cursive or underlined ...
    I can not find how to "printf" with colors or how to increase or decrease text size ...

    Please help me!
    Thank you
    bye

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    If that's possible, I'm pretty sure you can't do that from the printf() function. Maybe one of the veterans here may have an idea for how to do that, though.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    > do not know how to write colorful text, fat, cursive or underlined ...
    That's beyond the scope of what printf does. To do what you want would require more than just a console mode program, and I wouldn't recommend that so soon after starting to learn C.
    My best code is written with the delete key.

  4. #4
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    As Prelude said, printf simply writes plain text to standard output. However, certain platform independent methods have been devised to allow control codes to change the colour. A common standard for this is ANSI escape codes. Under MS-DOS (and possibly under a Windows DOS box) you need a driver ansi.sys loaded in order for them to work. See the link in this paragraph for more detail.

    In C, under any terminal that supports ANSI codes, the following example will output some text in green and red. I have illustrated two ways, directly in printf, or using an escape string (ansi_esc). There also exists control codes for bold, et cetera.
    Code:
    #include <stdio.h>
    int main(void)
    {
        char ansi_esc[] = { 27, '[', 0 };
        printf("%s32mThis is green\n%sm", ansi_esc, ansi_esc);
        printf("\033[31mThis is red\n\033[m");
        return 0;
    }
    Last edited by cwr; 10-14-2005 at 10:33 PM.

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    78
    On windows you can use the Win32 console API functions to use color. Don't waste time with trivial tasks like colored text. Instead try to tackle some real programming problems. Learn how to program a linked list, queue and hash table. If you're interested in games, create a maze generating program that solves itself... write a tetris game... what ever you think looks interesting, but do something that will challenge you.

    -Rog

  6. #6
    Registered User
    Join Date
    Oct 2005
    Posts
    3
    Thank you for your answers!
    My first Project is already finished, an "Who will be Millionaire" Text-only game : )

    Took me quite a while to figure out the controls and what will happen if you answer a false option ... But my result is not that great too :\

    But it works

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 04:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 04:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 09:50 AM