Having trouble C language debug step into process decimal point operator in a floating point sting of numbers. Example: 1234.5678, itoa() output stops at 4 and terminates out array string with '\0' Null char* pointer also an array. So we only get 1234\0 in the out array even after adding test for '.' seems to just skip over it like it's not really there. Thanks for any ideas to get these counts and floating-point decimal point for serial UART data without using printf().
Also strnlen() has same issue, counts only to the decimal point and C sizeof returns the count of 2 (1234.5678) characters are put in the array1={0.0} yet sizeof operator is in violation of clang definition below since it only returns count of 2 for the string. This may be vendor related string.h
#if defined(_INLINE) || defined(_STRLEN)
_OPT_IDEFN size_t strlen(const char *string)
{
size_t n = (size_t)-1;
const char *s = string;
do n++; while (*s++);
return n;
}
#endif /* _INLINE || _STRLEN */
size_t len = sizeof *varin;
sizeof object and sizeof(type name): yield an integer equal to the size of the specified object or type in bytes. (Strictly, sizeof produces an unsigned integer value whose type, size_ t, is defined in the header <stddef. h>.) An object can be a variable or array or structure. A type name can be the name of a basic type like int or double, or a derived type like a structure or a pointer.
```
/*****************************************************
*
*! Implementation of itoa()
*
* b\return converted character string
*
***************************************************/
char*
itoa(int16_t num, char* str, int base)//intmax_t
{
uintptr_t i = 0; //int
bool isNegative = false;
/* Handle decimal point explicitely with ASCII (".") */
if(num == '.')
{
//str[i++] = '.';
str[i] = 0x2E;
//
return str;
}
/* Handle unterminated end of string by adding NULL */
else if(num == ' ')
{
str[i] = '\0';
//
return str;
}
/* Handle 0 explicitely, otherwise Null string is printed for 0 */
if(num == '0') //0
{
str[i++] = '0';
//str[i] = '\0';
return str;
}
// In standard itoa(), negative numbers are handled only with
// base 10. Otherwise numbers are considered unsigned.
if (num < 0 && base == 10)
{
isNegative = true;
num = -num;
}
// Process individual digits
while (num != 0)
{
int16_t rem = num % base; //intmax_t
str[i++] = (rem > 9)? (rem-10) + 'a' : rem + '0'; //
num = num/base;
}
// If number is negative, append '-'
if (isNegative)
{
str[i++] = '-';
}
// Append string terminator
str[i] = '\0';
// Reverse the string
reverse(str, i);
return str;
}
```
/* Decls */
static float32_t varin[1] = {0.0};
*varin = dbytes;
static char varout[8];
/* Convert hexadecimal to ASCII codes
* terminate end NULL */
itoa(*varin, varout, 10);