Hello. This is my first post and I welcome any and all advice on this particular program I am writing. I am trying to take any int value and convert it to a constant address off an array. For instance, if I enter the value 8, the output should be 0x08 as a string. I suspect there maybe a simpler way of doing this, but I am at a loss. I get the following errors when I compile:
main.c:54: warning: passing arg 1 of `ConvertStringToTable' makes integer from pointer without a cast
main.c:57: error: syntax error before '(' token
main.c:57:17: warning: multi-character character constant
main.c: In function `ConvertStringToTable':
main.c:61: error: syntax error at end of input
Eventually I want to take micro controller output as an int value and produce a matching address which I will use for an on screen display, but I'd like to get this simpler version working first.
Code:#include <stdio.h> #include <string.h> #include <stdlib.h> // // defining constants const unsigned char charcodetable[] = { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A, }; const unsigned char ascii_table[] = { '1','2','3','4','5','6','7','8','9','0', }; unsigned char ConvertStringToTable (unsigned char data) { unsigned char outchar=0x99; unsigned int i; for (i=0; i< sizeof(ascii_table); i++) { if (data == ascii_table[i]) { outchar = charcodetable[i]; break; } } if (outchar!=0x99) { return outchar; } else { return data; } int main() { int num = 1; unsigned char buf[15]; unsigned char dummy; itoa (num, buf, 10); printf("%s\n", buf); do { dummy = ConvertStringToTable (buf); printf ("%s\n",dummy); } (dummy != '0x99'); System ("Pause"); return 0; }


