Welcome! Log In Create A New Profile

Advanced

printf not working in if() statement

Posted by Jacic 
printf not working in if() statement
November 11, 2010 11:50PM
I have this code:
#include 
#include 
#include 
#include 

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

//---------------------------------------------------------------------------------
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");
	
	printf("                                 PowerOffTo\n");
	printf("A: Idle mode(yellow)\nB: Standby mode(red)\nHOME: Exit to loader");

	while(1) {

		// Call WPAD_ScanPads each loop, this reads the latest controller states
		WPAD_ScanPads();

		// WPAD_ButtonsDown tells us which buttons were pressed in this loop
		// this is a "one shot" state which will not fire again until the button has been released
		u32 pressed = WPAD_ButtonsDown(0);

		// standby mode
		if(pressed & WPAD_BUTTON_B) SYS_ResetSystem(SYS_POWEROFF_STANDBY,0,0);
		
		//idle mode
		if(pressed & WPAD_BUTTON_A) SYS_ResetSystem(SYS_POWEROFF_IDLE,0,0);
		
		//exit to loader
		if(pressed & WPAD_BUTTON_HOME)
		{
		    //prinf("\n\nReturning to loader");
		    exit(0);
		}

		// Wait for the next frame
		VIDEO_WaitVSync();
	}

	return 0;
}
This code was taken from the template and modified for a quick demo, and works fine. However, when I uncomment out the printf() right before exit(0), I get:
73:7: warning: implicit declaration of function 'prinf'
and
73: undefined reference to `prinf'
Does anyone have any ideas on how to fix this?
Re: printf not working in if() statement
November 12, 2010 02:09AM
I'm afraid there is nothing that can be done to fix that. It'll take years to debug the code and find out where the error lies.

Well, that's not totally true... you can try something really really dangerous and you risk ruining your computer.... but if you wanna try it. Proceed with caution with the following steps:


1. Put the letter "t" between the letter "n" and the letter "f" in the word "prinf"

2. Cross your fingers.

good luck my friend!



Edit: just a little humor! :D



Edited 1 time(s). Last edit at 11/12/2010 02:12AM by mdbrim.
Re: printf not working in if() statement
November 12, 2010 02:09AM
Really!!!

73: undefined reference to `prinf'
Re: printf not working in if() statement
November 12, 2010 04:28AM
*facepalm* Well, thats what you get when youre in a hurry and dont take time to completely read error messages! :)
Thanks for pointing that out.
Sorry, only registered users may post in this forum.

Click here to login