inchar(NULL) is giving wrong values

Posted By: alibaba

inchar(NULL) is giving wrong values - 09/27/15 08:40

Why is inchar giving bad values? Changing literally anything in this code fixes it, like removing the wait, removing the parameter whatever.

Code:
#include <acknex.h>
#include <default.c>

STRING* testStr="abcd";

void input(STRING* str)
{
	while(1)
	{
		char lol=inchar(NULL);
		printf(lol);
		wait(1);
	}
}
void main()
{
	input(testStr);
}



EDIT: Also having lol as var and then casting as char gives bad values.
Posted By: Ch40zzC0d3r

Re: inchar(NULL) is giving wrong values - 09/27/15 09:41

You cant do "printf(lol);" because every char pointer/array has to be terminated using "0" called the string terminator.
Posted By: Kartoffel

Re: inchar(NULL) is giving wrong values - 09/27/15 10:02

^: also printf needs a specific syntax, consisting of a static format string, followed by as many vars as you want to display.

so it's printf("%c", lol); for a single char.

EDIT: oh, and try putting a wait(1); between the inchar and the printf.
I think I had to use something similar when I made a japanese kana input for someone.
Posted By: alibaba

Re: inchar(NULL) is giving wrong values - 09/27/15 11:55

Okay solved! Sorry I have completely forgotten to null-terminate the char >.<"

Thanks!
© 2024 lite-C Forums