Thread: Struct array - char array

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    4

    Struct array - char array

    Hello,

    I am trying to run the following code (on a NDS gameconsole) but it doesn't run for some reason. Can anyone tell me what i am doing wrong?

    Code:
    	struct node
    	{  	char title[26];
    		char description[201];       
    		char datum[21];
    	};
    
    	struct node nodes[10];
    	
    	nodes[0].title[0]='t';
    	nodes[0].title[1]='i';
    	nodes[0].title[2]='t';
    	nodes[0].title[3]='l';
    	nodes[0].title[4]='e';
    	nodes[0].title[5]='1';
    	nodes[0].title[6]='\0';
    	nodes[1].title[0]='t';
    	nodes[1].title[1]='i';
    	nodes[1].title[2]='t';
    	nodes[1].title[3]='l';
    	nodes[1].title[4]='e';
    	nodes[1].title[5]='2';
    	nodes[1].title[6]='\0';
    	
    	sprintf("%s\n",nodes[0].title);
    	sprintf("%s\n",nodes[1].title);
    Thanks

    Veda88

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    4
    Oh damn, 3 times, bad internet connection here....

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'm not familiar with your game console, but C programs always need a main() function, and usually the line, #include <stdio.h>, before said main().

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    4
    The code shown in the first post is just a snippet. I have included the stdio.h, stdlib.h and some nds specific header files.
    Also the main function is present as expected:
    int main(void) {

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So, sprintf is supposed to print to a string, not the screen, isn't it? Why aren't you getting compile errors about mismatched types? (Edit: Well, warnings about const things are always a bit wonky, I suppose. But the first string is where the answer is supposed to go, and the second string is the format string.)
    Last edited by tabstop; 09-25-2009 at 08:32 AM.

  6. #6
    Registered User
    Join Date
    Jun 2009
    Posts
    4
    Hello,
    I changed the sprintf to printf, but it didn't change a thing. It is still just printing nothing

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Which brings us to point #2. Not familiar with NDS, but: is printf the normal method for putting things on a DS screen? It's possible, I suppose, but I wouldn't expect it.

  8. #8
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Are you compiling for ARM? If not you will need a devkit for it. I have a DS and want to do some coding for it, but I never seem to get the time. Once you have a devkit it would probably be worth learning to use a library such as palib (tutorial on site), which has function to blit text to the screen, draw sprites and handle input including simple pattern recognition for with the stylus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Looking for a way to store listbox data
    By Welder in forum C Programming
    Replies: 20
    Last Post: 11-01-2007, 11:48 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

Tags for this Thread