How to turn an int (number) into a char (string) in C
I'm trying to move an int (number) to a char (string). I use the following code:
int adcResult = 333;
char h = (char)adcResult;
char h1 = (char)ADC1BUF0;
сhar h2= itoa(adcResult);
puts_lcd( h2 ,3); // из за этой строки не собирается ошибки пишет ;_;
...
...
void puts_lcd( unsigned char *data, unsigned char count )
{
while ( count )
{
lcd_data( *data++ );
count --;
}
}
But it displays a complete nonsense on the debug board screen(Explorer 16).
The #include <iostream.h>
library is not supported.
Due to the fact that the program is written in MPLAB for a microcontroller of the dsPIC33 family (for some reason it does not support this library).
0
1 answers
Function itoa.
First parameter: the number to be converted to a string (int)
The second parameter: a pointer to the string where the converted number should be written.
The third parameter: The number system used to translate the number
Using the itoa
function in your case:
int adcResult = 333; // исходное число
char adcString[15]; // буфер, в которую запишем число
itoa(adcResult, adcString, 10); // вместо третьего параметра
// можете написать нужное вам значение
// например перевести в 16-ричную с.счисления
puts_lcd
it should be called as follows:
puts_lcd(adcString, strlen(adcString));
4
Author: acade, 2018-08-08 13:53:56