You are not logged in.
I am doing some debugging in my program and I have a function that returns an int. I want to display that value on the screen but no matter how many different ways I try and convert it, when I display it the Wii always freezes. Here is one of many ways I tried.
int *test = Menu_Device(); char buf[20]; sprintf(buf, "%d", *test); GRRLIB_Printf(20, 328, tex_font, 0xFFFFFFFF, 1, buf);
I even tried this.
int *test = Menu_Device(); char *buf = (char*)test; GRRLIB_Printf(20, 328, tex_font, 0xFFFFFFFF, 1, buf);
Offline
Try to add some validation:
int *test = Menu_Device(); if(test != NULL) { // Check that the pointer is pointing to something char buf[20]; sprintf(buf, "%d", *test); GRRLIB_Printf(20, 328, tex_font, 0xFFFFFFFF, 1, buf); }
PS: This question has nothing to do with GRRLIB, next time try another forum
Offline
In a way it does becuase the GRRLIB_Printf function always causes it to freeze
Offline
Try initializing the buffer:
int *test = Menu_Device(); if(test != NULL) { // Check that the pointer is pointing to something char buf[20] = ""; sprintf(buf, "%d", *test); GRRLIB_Printf(20, 328, tex_font, 0xFFFFFFFF, 1, buf); }
If that does not work, try commenting the line with GRRLIB_Printf and tell me what is happening without the line.
Offline
I tried it with validation and intializing the buffer but it still freezes. I even comment out the print function and it still freezes. So the sprintf causes it to freeze.
Offline
Could you tell me what Menu_Device() is returning, is it really an int *? Paste the declaration of the function please.
celinedules wrote:
So the sprintf causes it to freeze.
I knew it's was not a GRRLIB question
Offline
int *Menu_Device(void);
For testing I just return 1 in the function.
Offline
celinedules wrote:
Code:
int *Menu_Device(void);For testing I just return 1 in the function.
Does it really need to be a pointer? If you return 1, this wrong. You should return a pointer to the value 1.
If you want more help, please provide the code from Menu_Device or I wont be able to help further.
Offline
This is what I have. There is other stuff in there but its commented out so it doesn't do anything.
int *Menu_Device(void) { u32 timeout = 30; s32 ret; ret = WBFS_Init(1, timeout); return 1; }
Offline
Why not just use:
int Menu_Device(void) { u32 timeout = 30; s32 ret; ret = WBFS_Init(1, timeout); return 1; }
Without using a pointer.
Offline
That worked. I really have no idea why I was using a pointer to begin with. i am sure there was some reason but oh well.
Thanks
Offline