Thomas Flennert

Own itoa

Discussion created by Thomas Flennert on Aug 26, 2008
Latest reply on Aug 29, 2008 by Pascal Irrle
Hello I have a problem with converting int to char.
I don't have access to extras.h
And sprintf only givs back junk characters
I have also tried the union example that is placed here on the forum but no success
I have just simplefied the function to see what is going wrong but the problem is still there
void itoa() {
  unsigned int n = 12345;
  unsigned char i = 0;
  unsigned char s[7];
  do {
    s[i++] = (unsigned char)('0' + (n % 10));    // This works givs 54321 on RS232 or on LCD
  } while ((n /= 10) > 0);
  s[i] = '\n';
    do{}while(RS232_SendChar(s[i]));        // This doesent givs X4X2X   where X  is random
And if i declare s[7] as static char i get 5X3X1  where X  is random
What am I doing wrong?
I use a 56F8357 and CW 8.1.1a build 7168
Hope someone could give me a helping hand because this is not what I should spend my time on.