Welcome! Log In Create A New Profile


cannot use scanf or gets

Posted by TheDrev 
cannot use scanf or gets
May 26, 2010 03:35PM
I can't do a simple scanf ?!

in the example/wii/template/source/template.c I've added after the hello world! :
	printf("Hello World!");

	char cmd[32];
	scanf("%s", cmd);
	printf("you said -> %s\n", cmd);

the scanf don't wait the user input and the program continue...
It's the same with gets or fgets
the output is
you said -> Ç? (? is the mars symbol [en.wikipedia.org])

I'm very happy that the wii reconize my virility, but I'd perfer that it wait for input...

After that I've flushed the input buffer with a
    int c = 0;
    while (c != '\n' && c != EOF){c = getchar();}

but the scanf don't wait more, the only differance is that the output is empty
you said ->

I've added -lwiikeyboard in the Makefile, so the LIBS is now :
LIBS := -lwiiuse -lbte -logc -lm -lwiikeyboard

any ideas ?

Edited 1 time(s). Last edit at 05/26/2010 03:36PM by TheDrev.
Re: cannot use scanf or gets
May 26, 2010 03:45PM
I'm not sure if scanf even works with USB keyboards on the Wii. But have you called KEYBOARD_Init?
Re: cannot use scanf or gets
May 26, 2010 04:32PM
I did not know that such init needed to be done..
I've take some code from [wiibrew.org] example and now it works ! Thanks a lot !
I guess that without this init, some random characters are passed to the input buffer.... ?

Edit :
With the [wiibrew.org] I cannot use space, which behave like a return
and backspace which does noting. I guess this is a problem with the keyboard callback function,
I check this out, the most important thing is to have the space key working...

Edited 2 time(s). Last edit at 05/26/2010 07:06PM by TheDrev.
Sorry, only registered users may post in this forum.

Click here to login