cancel
Showing results for 
Search instead for 
Did you mean: 

Issue casting an integer type to char type/string

TombrownBottom
Associate III

Here is the method defined in the .h file:

void ILI9341_DrawText(const char* str, const uint8_t font[], uint16_t X, uint16_t Y, uint16_t color, uint16_t bgcolor);

the method defined in the .c file:

void ILI9341_DrawText(const char* str, const uint8_t font[], uint16_t X, uint16_t Y, uint16_t color, uint16_t bgcolor) { uint8_t charWidth; /* Width of character */ uint8_t fOffset = font[0]; /* Offset of character */ uint8_t fWidth = font[1]; /* Width of font */ while (*str) { ILI9341_DrawChar(*str, font, X, Y, color, bgcolor); /* Check character width and calculate proper position */ uint8_t *tempChar = (uint8_t*)&font[((*str - 0x20) * fOffset) + 4]; charWidth = tempChar[0]; if(charWidth + 2 < fWidth) { /* If character width is smaller than font width */ X += (charWidth + 2); } else { X += fWidth; } str++; } }
View more

If in the main.c file I invoke the following command:

v

The TFT LCD display, displays 99 correctly.

 

My issue is that if I want to pass an integer into the method it fails to complile.

 

A simple example would be that I declare and int, (int number =1;)

then invoke:ILI9341_DrawText(number, FONT4, 4, 2, WHITE, BLACK);

Moving from Arduino has been difficult as coding in Arduino allows for use of a simple cast.

 

Can someone advise how to get over this issue? Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
TombrownBottom
Associate III

Ok, I have worked it out myself. For the benefit of others.......

I have added:

char text[10];// create a string to hold the int value after conversion to string

 

itoa(number, text, 10);//function to convert the int into a string (3rd argument 10 = base 10)

Then the method:

ILI9341_DrawText(text, FONT4, 4, 2, WHITE, BLACK);

produces the correct output.

 

 

View solution in original post

1 REPLY 1
TombrownBottom
Associate III

Ok, I have worked it out myself. For the benefit of others.......

I have added:

char text[10];// create a string to hold the int value after conversion to string

 

itoa(number, text, 10);//function to convert the int into a string (3rd argument 10 = base 10)

Then the method:

ILI9341_DrawText(text, FONT4, 4, 2, WHITE, BLACK);

produces the correct output.