Hello everybody,
I'm trying to print the value of a int variable to one LCD but it's not working properly, I've tried many things but I would like to know how can I include a int variable to a normal a string that I want to print to the LCD.
I can only print normal texts to the LCD but without variables, for example doing this:
char *text="Hello world";
while (*text)
{
senddatatoLCD (*text++); //Function made to send data to LCD in 2 lines using 4 bits only.
}
I would like to build a string with value of int variable already included and then just send this string with a while loop as I've on the example shown before.
Something like this: sprintf (*string, "The value: %d", var);
and the use the *string to print it to the LCD.
Does someone knows how to do it?
Thanks in advance.
This is very basic C programming. You need "string" to be an ARRAY to define some storage for sprintf to write to.
char vString[100]; char *pText; int nVar = 123 sprintf(vString, "The value: %d", nVar); pText = vString; /* this is the same as "pText = &vString[0];" */ while (*pText) { ... And so on, the same as before ...
See if you can get an old K&R C book and work through that.
Tom