Welcome! Log In Create A New Profile

Advanced

[RESOLVED] Wii C language Noob.

Posted by umby24 
[RESOLVED] Wii C language Noob.
November 07, 2009 06:22AM
K, so I am a Visual Basic .NET Programmer, trying to get into some programming for the wii as well as the psp, so I decided to make a simple navigateable menu.. Simple enough right? I guess not.

I finally killed off all the errors (which left me with about 2,00000000000000000000000000000 warnings) and ran it on my wii.. It didn't preform Like i hoped at all, and ended up giving me a code exception and crashing the wii.

Now after trying to fix it, I have a crap load of errors..

I am devoloping on Linux, Ubuntu Karmic.

The output I'm getting:

/home/tommy/Projects/examples/wii/NavMenu/source/template.c: In function 'draw_text':
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:81: warning: passing argument 1 of 'printf' makes pointer from integer without a cast
/home/tommy/Projects/examples/wii/NavMenu/source/template.c: In function 'Process_A_button':
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:86: error: incompatible types in assignment
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:89: error: incompatible types in assignment
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:92: error: incompatible types in assignment
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:95: error: incompatible types in assignment
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:99: warning: passing argument 1 of 'draw_text' makes integer from pointer without a cast
/home/tommy/Projects/examples/wii/NavMenu/source/template.c: In function 'Process_updown':
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:103: warning: comparison between pointer and integer
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:103: warning: comparison with string literal results in unspecified behaviour
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:113: warning: comparison between pointer and integer
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:113: warning: comparison with string literal results in unspecified behaviour
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:124: warning: passing argument 1 of 'draw_text' makes integer from pointer without a cast
/home/tommy/Projects/examples/wii/NavMenu/source/template.c: In function 'main':
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:140: warning: passing argument 1 of 'Process_updown' makes integer from pointer without a cast
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:143: warning: passing argument 1 of 'Process_updown' makes integer from pointer without a cast
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:146: error: incompatible types in assignment
/home/tommy/Projects/examples/wii/NavMenu/source/template.c:149: warning: passing argument 1 of 'draw_text' makes integer from pointer without a cast
make[1]: *** [template.o] Error 1
make: *** [build] Error 2




The Source code is..


#include 
#include 
#include 
#include 

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
int selected=1;
char current[30];
//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	// Initialise the video system
	VIDEO_Init();
	
	// This function initialises the attached controllers
	WPAD_Init(); 
	
	// Obtain the preferred video mode from the system
	// This will correspond to the settings in the Wii menu
	rmode = VIDEO_GetPreferredMode(NULL);

	// Allocate memory for the display in the uncached region
	xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
	
	// Initialise the console, required for printf
	console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
	
	// Set up the video registers with the chosen mode
	VIDEO_Configure(rmode);
	
	// Tell the video hardware where our display memory is
	VIDEO_SetNextFramebuffer(xfb);
	
	// Make the display visible
	VIDEO_SetBlack(FALSE);

	// Flush the video register changes to the hardware
	VIDEO_Flush();

	// Wait for Video setup to complete
	VIDEO_WaitVSync();
	if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

	// The console understands VT terminal escape codes
	// This positions the cursor on row 2, column 0
	// we can use variables for this with format codes too
	// e.g. printf ("\x1b[%d;%dH", row, column );
	printf("\x1b[2;0H");


void Drawmenu () {
   if (selected == 1 ) {
     printf(">> Say Hello to Dad\n");
     printf("Say hello to mom\n");
     printf("Say hello to dill\n");
     printf("Say hello to dog\n");
   }
   if (selected == 2 ) {
     printf("Say Hello to Dad\n");
     printf(">> Say hello to mom\n");
     printf("Say hello to dill\n");
     printf("Say hello to dog\n");
   }
   if (selected == 3 ) {
      printf("Say Hello to Dad\n");
      printf("Say hello to mom\n");
      printf(">> Say hello to dill\n");
      printf("Say hello to dog\n");
   }
   if (selected == 4 ) {
     printf("Say Hello to Dad\n");
     printf("Say hello to mom\n");
     printf("Say hello to dill\n");
     printf(">> Say hello to dog\n");
   }
}

void draw_text (char message) {
printf(message);
}

void Process_A_button () {
if (selected == 1) {
current="Hello Dad!";
}
if (selected == 2) {
current="Hello Mom!";
}
if (selected == 3) {
current="Hello Dill!";
}
if (selected == 4) {
current="Hello Angel!";
}
VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_BLACK);
Drawmenu();
draw_text(current);
}

void Process_updown (char upydown) {
if (upydown=="up") {
   if (selected == 1) {
    selected=4;
   }
   else
   {
   selected--;
   }
}

if (upydown=="down") {
  if (selected == 4) {
  selected=1;
  }
  else
  {
  selected++;
  }
  }
  VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_BLACK);
  Drawmenu();
  draw_text(current);
}


Drawmenu();

	while(1) {

		// Call WPAD_ScanPads each loop, this reads the latest controller states
		WPAD_ScanPads();
                u16 pressed = WPAD_ButtonsUp(0);

                if ( pressed & WPAD_BUTTON_A ) {
                  Process_A_button();
                }
                if ( pressed & WPAD_BUTTON_UP ) {
                  Process_updown("up");
                }
                if ( pressed & WPAD_BUTTON_DOWN ) {
                  Process_updown("down");
                }
		if ( pressed & WPAD_BUTTON_HOME ) {
                 current="Exiting";
                 VIDEO_ClearFrameBuffer (rmode, xfb, COLOR_BLACK);
                 Drawmenu();
                 draw_text(current);	
                 exit(0);
		}
         VIDEO_WaitVSync();
	}


	return 0;
}


The first thing that is making me wtf is that I set the Variable "Current" and I had it set as a text variable (Char)

right? so there should be no issue, in setting it like this: current="Hello World!"; Right?

Well. Apperntly not, which I have no reason why not.


as it implys that I am trying to set a number?


with.. :

/home/tommy/Projects/examples/wii/NavMenu/source/template.c:86: error: incompatible types in assignment



I see no reason for this error.. I am setting text to a text variable, what is the issue?



Any help is appreciated..



Edited 1 time(s). Last edit at 11/07/2009 03:34PM by umby24.
Re: Wii C language Noob.
November 07, 2009 06:59AM
You should read the C basics. Functions are not declared inside other functions, you are declaring (or attempting to) some functions inside main. It's similar to functions/modules/procedures declaring/calling in VB, where each object event has its own instructions and you can call them from another event instead of copying the whole code.

The only advice I can give you is to read C documentation, specifically functions declaration since it's the only thing you did terribly wrong (skimmed your code). You're supposed to come here knowing those things. You should not have many problems. You don't seem to be completely lost and you stated you are a programmer... show it off.

Tell us how it went!
Aruskano

Edit: Lol. I didn't finish to read your post. Char is a type to hold characters (xD), not to hold strings. That's why you can't assign a string directly to a variable of this type. Read about that too (Strings in C or so), you may want to overlook pointers atm.



Edited 1 time(s). Last edit at 11/07/2009 07:07AM by Aruskano.
Re: Wii C language Noob.
November 07, 2009 03:34PM
K thanks for your help, I feel retarded with the whole putting a function within a function now... and I still could use string variables.. but meh.

I converted it to use numbers instead, and not a single warning or error to be found. and it works as i expected now.


Thanks again..


EDIT: Except now at random times it decides to give me the gift of a beautiful DSI error whenever I press the buttons too fast for it or w/e..



Edited 1 time(s). Last edit at 11/07/2009 03:36PM by umby24.
Re: [RESOLVED] Wii C language Noob.
November 23, 2009 09:13PM
Repost the code and we can see if we can help you. :o
Re: [RESOLVED] Wii C language Noob.
December 06, 2009 01:21PM
If you want to use the strings, just declare current as:
char *current; (pointer to a char array aka c string).
Since you never allocate memory, and it will just point to string constants, you don't have to worry about memory leaks with this.
But for advanced string operations, you need to do memory management.
So you might want to look into malloc, calloc, realloc, free and memset.
Re: [RESOLVED] Wii C language Noob.
December 06, 2009 01:43PM
You can as well try messing with string.h file to make stricte string variables but since there is a way to make string from char it's not that much necessary
Plus on next time when including code try to paste it with spaces here:
#include < file.h >
because this forum somehow tries to parse < > as HTML tags even that as .h files they aren't them, that makes for example in Your code empty #include lines :P
Re: [RESOLVED] Wii C language Noob.
February 01, 2010 03:36AM
Get the Kernighan and Richie "The C Programming Language" book. Commonly referred to as "The Bible." It's awesome and concise.

-H
Re: [RESOLVED] Wii C language Noob.
February 01, 2010 11:33AM
Quote
unhuman
Get the Kernighan and Richie "The C Programming Language" book. Commonly referred to as "The Bible." It's awesome and concise.

-H
And just as the Bible it's a bit outdated and has many zealots following it. But it should provide you with a good start. There are also many webtutorials, but I recommend you stay away from those as 80% of them is just bad for you. (Anyone know any good basic C tutorial sites?)
Re: [RESOLVED] Wii C language Noob.
February 01, 2010 05:42PM
I liked cplusplus.com. No, it's not C, but it's got the basics of C++ at least, that's something.
Re: [RESOLVED] Wii C language Noob.
February 25, 2010 05:22AM
Actually the functions within functions is not how C is usually written but it seems to work.

I have code that generates some dynamic variables and other dynamic code which uses these dynamic variables. This makes it more difficult to pass variables to the functions because the number and types of variables are not know before hand. I know that it is an odd case and I could probably write functions with unlimited paramaters so that you could pass everything back and forth nice and proper, but when I placed my functions within the main function it resolved these problems because the functions gained access to all the main level variables.

Yes. Agreed. My case is very odd and definitly not the standard coding practice...but functions within functions work.

I am a VB user (most of the time) so my C code is a little rusty (and I might be confusing it with my Java work that I did a while back) but isn't functions within functions how you implement classes in C? You make a function which represent your class and then, within that function, you add your functions to implement all the methods that your class will have.
Sorry, only registered users may post in this forum.

Click here to login