Welcome! Log In Create A New Profile

Advanced

printf not working for %s const char

Posted by owen 
printf not working for %s const char
July 13, 2011 05:37PM
I have this problem when I try to print a const char * using printf nothing outputs on the television screen. If a print a constant it appear fine but if I use a %s nothing is outputed. what am I doing wrong?

my C code looks like this;
engine_console()
Object3D_LoadModel( "model/sspaceship01.obj", "model/sspaceship01.png", 2 );

and the function I use to print to the screen looks like; [codepad.org]
Re: printf not working for %s const char
July 13, 2011 07:24PM
Looking at
Object3D_LoadModel(const char *fn, const char * fn2, int p )

You need use a pointer(s) when passing the parametets

char Text1[] = "model/sspaceship01.obj"
char Text2[] = "model/sspaceship01.png",

Object3D_LoadModel( Text1, Text2, 2 );
// or another way to do the same thing ... Object3D_LoadModel( &Text1[0], &Text2[0], 2 );
Re: printf not working for %s const char
July 13, 2011 08:04PM
OMG that looks annoying. Going to try it later and see if that solves the problem.
Re: printf not working for %s const char
July 14, 2011 01:53AM
Nope, still doesn't printf the line. I declared a const char variable and it still doesn't work. Once the I put the %s into the format string it doesn't print anything.
Re: printf not working for %s const char
July 14, 2011 09:31AM
How odd, can you post the latest code example. Looks like I've overlooked something.
Also, with printf if needed you can just print a string no need for %s, but what you are saying should still work.

char *MystringPointer = "Test123";
printf( MystringPointer );
printf( "message is %s", MystringPointer );

As a test try this code after your console_init, it should work fine.
Re: printf not working for %s const char
July 14, 2011 03:46PM
Tried that too, doesn't work. seems to be something specific with the wii because I can't find anybody have any problem with it on the internet. latest: [codepad.org]
Re: printf not working for %s const char
July 14, 2011 09:36PM
These might help tracking down this problem.... (maybe some kind of display problem - but feels like its something else not here!)

(1) Direct the output to file (SD card), see if it looks ok from there. (I find using ‘WiiXplorer’ is a nice way to view things, I use it for everything including copying files from the PC onto the SD card to test before a release.) see code
(2) Use Dolphin (wii emulator) to view your printf’s – they come up in log view, this is very useful.
(3) Calling VIDEO_Flush, think it refreshes the nextFb which console uses (you are).
(4) Not sure, maybe call printf on the correct framebuffer, I don't get printf to display at exit unless a toggle to the first buffer - the console is normaly initialised at start-up pointing at first frame buffer.

// Found some old code of mine on my backup drive, nasty hard coded numbers so look out.
// TracePrintf("My message is: %d %s", 16386, "is a number") ; 
#include 
#include 
#include   

TracePrintf ( char* Format, ... )
{
	va_list	ArgList;
	char	Str[512];
	FILE*	file;
	static int	FirstTime = 1;

	if ( FirstTime )
		file = fopen ( "trace.log", "wt" );
	else
		file = fopen ( "trace.log", "at" );
	if ( file == NULL )
		return;
	FirstTime = 0;

	va_start ( ArgList, Format );
	_vbprintf ( Str, sizeof(Str), Format, ArgList );
	va_end ( ArgList );

	fprintf ( file, "Message: %s(%d): %s\n", DebugFile, DebugLine, Str );
	fflush ( file );

	fclose ( file );
}
Re: printf not working for %s const char
July 14, 2011 09:41PM
Just thinking it’s not point 4 - that happens for me as the consoles callback is stops.
Re: printf not working for %s const char
July 14, 2011 11:42PM
I know that it the string is there, because the file load that I do after works perfectly, I just want to print what I'm loading at the moment on the screen. Its not crucial, mostly for debugging the lua scripts. I have 2 more things that I am going to try this evening before I give up on it all together.
Re: printf not working for %s const char
July 15, 2011 02:48PM
Tried setting a range[255], hmmmm, still doesn't work. I even tried searching snesgx and grrlib source and they don't seem to use it for %s either. hmm...I guess I'll have to skip leave this for some other time. Thanx for your help Titmouse.
Re: printf not working for %s const char
July 15, 2011 06:48PM
You need to reduce your code to the smallest possible complete program that still reproduces the problem. It's obviously caused by something you're not showing since simple test code works fine.

Possibly something is turning on buffered output for stdout, try "fflush(stdout)" after the printf calls.
Re: printf not working for %s const char
July 15, 2011 07:20PM
Tueidj has said what I was thinking all along, as I final test (if this does not work maybe delete \devkitPro\libogc downloading a fresh copy - as I feel is this does not work then how many other things may go bad too)

Take the example template.c found in...
devkitPro\examples\wii\template\source & add this code
void MyPrintf(char* pText)
{
	printf("Message is %s",pText);
}

// Call it just before start of the while loop

MyPrintf("Testing123");

p.s my fist post was poo - you can use strings directly



Edited 1 time(s). Last edit at 07/15/2011 07:23PM by Titmouse.
Re: printf not working for %s const char
July 25, 2011 06:50PM
I was working on some Lua stuff over the weekend and I noticed that whenever I got a crash screen I would see that the data that printf() is out putting about the debug string. More than likely something is wrong with my console video code or a GRRLIB setting is causing it not to output. Either way at least I know now that its not the printf(). :)
Sorry, only registered users may post in this forum.

Click here to login