You are not logged in.

  • Index
  •  » General Help
  •  » [RESOLVED] Casting a number to a string and displaying the results

#1 2009-05-05 17:38:41

celinedules
Member

[RESOLVED] Casting a number to a string and displaying the results

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.

Code:

int *test = Menu_Device();
char buf[20];
sprintf(buf, "%d", *test);
GRRLIB_Printf(20, 328, tex_font, 0xFFFFFFFF, 1, buf);

I even tried this.

Code:

int *test = Menu_Device();
char *buf = (char*)test;
GRRLIB_Printf(20, 328, tex_font, 0xFFFFFFFF, 1, buf);

Offline

 

#2 2009-05-05 19:06:02

Crayon
Bad Mother Fucker

Re: [RESOLVED] Casting a number to a string and displaying the results

Try to add some validation:

Code:

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

 

#3 2009-05-05 20:55:20

celinedules
Member

Re: [RESOLVED] Casting a number to a string and displaying the results

In a way it does becuase the GRRLIB_Printf function always causes it to freeze

Offline

 

#4 2009-05-05 21:40:30

Crayon
Bad Mother Fucker

Re: [RESOLVED] Casting a number to a string and displaying the results

Try initializing the buffer:

Code:

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

 

#5 2009-05-05 22:50:29

celinedules
Member

Re: [RESOLVED] Casting a number to a string and displaying the results

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

 

#6 2009-05-05 23:10:26

Crayon
Bad Mother Fucker

Re: [RESOLVED] Casting a number to a string and displaying the results

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 wink

Offline

 

#7 2009-05-05 23:14:48

celinedules
Member

Re: [RESOLVED] Casting a number to a string and displaying the results

Code:

int *Menu_Device(void);

For testing I just return 1 in the function.

Offline

 

#8 2009-05-05 23:21:35

Crayon
Bad Mother Fucker

Re: [RESOLVED] Casting a number to a string and displaying the results

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

 

#9 2009-05-05 23:25:29

celinedules
Member

Re: [RESOLVED] Casting a number to a string and displaying the results

This is what I have. There is other stuff in there but its commented out so it doesn't do anything.

Code:

int *Menu_Device(void) {

    u32 timeout = 30;
    s32 ret;
    
    ret = WBFS_Init(1, timeout);    
    
    return 1;
}

Offline

 

#10 2009-05-05 23:27:36

Crayon
Bad Mother Fucker

Re: [RESOLVED] Casting a number to a string and displaying the results

Why not just use:

Code:

int Menu_Device(void) {

    u32 timeout = 30;
    s32 ret;
    
    ret = WBFS_Init(1, timeout);    
    
    return 1;
}

Without using a pointer.

Offline

 

#11 2009-05-06 01:33:53

celinedules
Member

Re: [RESOLVED] Casting a number to a string and displaying the results

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

 
  • Index
  •  » General Help
  •  » [RESOLVED] Casting a number to a string and displaying the results

Board footer

Powered by FluxBB