Thread: Change text color

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    2

    Question Change text color

    Hi, I am new to programming with C and I am trying to create something for the Nintendo DS. What I have now is very basic but even with the simple things like changing the color of a char array gives me a lot of problems. I now have the following:

    helloworld.c
    Code:
    #include"helloworld.h"
    
    
    void hello_world()
    {
    char text[] = "Hello World";
        int i;
        int textLength = strlen(text);
    
    
        for (i = 0; i < textLength; i++)
        {
    /* Change the color of the letter here before printing it to the screen */
    
    
            printf("%c", text[i]);
        }
    }
    
    
    void loop()
    {
        while (true)
        {
    
    
        }
    }
    
    
    int main()
    {
        consoleDemoInit();
        hello_world();
        loop();
    return 0;
    }
    helloworld.h
    Code:
    #ifndef HELLOWORLD_H_
    #define HELLOWORLD_H_
    
    
    #include<nds.h>
    #include<stdio.h>
    
    
    #define true 1
    #define false 0
    
    
    void hello_world();
    void loop();
    
    
    #endif
    I tried a lot of things to change the color of each char but without success. Most of the times I get the error "Undefined reference to 'xxx'". The code that I have now works and compiles but how to change the text color? Sorry if this post is duplicated but all the solutions I found on this forum and other forums did not work for me. I am using Eclipse Indigo as my IDE on MacOSX Snow Leopard.

    Any help would be greatly appreciated.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > #include<nds.h>
    Well you're going to have to look through this file, and any other platform specific files, to see what mention of "text" and "color" you can find.

    Anything other than monochrome text in a single terminal font will require something specific to the NDS.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by JustRonald View Post
    Any help would be greatly appreciated.
    Is there no documentation for the nintendo library you're using?
    Seems to me a bit of reading is in order...

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    2
    There is not really good documentation about this library on the internet so it is a bit hard to find out. Anyway, after a lot of searching I found a solution to change the text color:

    Code:
    void hello_world()
    {
    char text[] = "Hello World";
    	int i;
    	int textLength = strlen(text);
    
    
    	for (i = 0; i < textLength; i++)
    	{
    		int color = i + 31;
    		printf("\x1b[%dm%c", color, text[i]);
    	}
    }
    Thanks for the reply's.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by JustRonald View Post
    There is not really good documentation about this library on the internet so it is a bit hard to find out. Anyway, after a lot of searching I found a solution to change the text color:
    Glad you found a solution... but you're going to keep running into this "lack of documentation" problem over and over again as you work ever more deeply into the API... Maybe a different library is in order?

    (It should come as no surprise that the documentation for complex libraries is often more important than the code itself...)

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I suggest trying these to see if they work.

    ASCII Table &#45; ANSI Escape sequences

    Tim S.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Really?? The Nintendo DS uses ANSI escape codes for color? /incredulous


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do i change backround color and text color?
    By Nathan the noob in forum C++ Programming
    Replies: 1
    Last Post: 02-17-2009, 04:39 AM
  2. Change text color in C
    By IndioDoido in forum C Programming
    Replies: 9
    Last Post: 04-15-2007, 05:54 AM
  3. change color text?
    By k4z1nh0 in forum C Programming
    Replies: 4
    Last Post: 03-15-2005, 11:41 AM
  4. How can i change the text color?
    By ^DJ_Link^ in forum C Programming
    Replies: 3
    Last Post: 01-12-2004, 04:21 PM
  5. How do you change the color of the text?
    By NewbieVB in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2002, 02:25 PM