I'm a novice trying to convert a float variable to an ascii string and it's not going too well.
I'm using MPLABx + XC8 lite + P18LF14k22
I've got a temperature value as a float that I want to convert to an ASCII string.
Attached below is a grab of the output from the code I'm trying out.
The conversion is only doing the first character. In the example its the '-' sign.
I'm sure this is because I'm not specifying the length of the output char array.
However if I try to declare the array with say 8 elements as below:
unsigned char buf[8]; //temp ascii string
........the compiler balks at the ftoa() line.
How should I be implementing this?
Thanks
My code:
char * buf; // <<<< I don't think this is declared correctly
float input = -14.25685; //test value 1
//float input = 52.54821; //test value 2
int status;
buf = ftoa(input, &status);
This is from the XC8 Compiler User Manual:
FTOA
Synopsis
#include <stdlib.h>
char * ftoa (float f, int * status)
Description
The function ftoa converts the contents of f into a string which is stored into a buffer
which is then return.
Example:
#include <stdlib.h>
#include <stdio.h>
void
main (void)
{
char * buf;
float input = 12.34;
int status;
buf = ftoa(input, &status);
printf("The buffer holds %s\n", buf);
}