Beware arithmetic against character constants. EBCDIC happens.
Oh, you mean having an output array like:
char[] output = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', ... , 'Z' };
And when you calculate each output component in the output base, you then use it as an index into this table? Like if the value was 227 (base10) and the output was in base 14, so we extract out component values of: 196 + 28 + 3 (base 10) or 1x14^2 + 2x14^1 + 3x14^0. So we feed in 1,2,3 into the table, and get out '1', '2', '3'?
Or do you mean that we have:
char output[NUM_BASES][NUM_POWERS_OF_BASE][VALUES] ?
Because we'd still have to worry about the size of NUM_POWERS_OF_BASE, which would be tied to the output string length.
So post your code and we can comment on it!
#include "elegant.h" /* let's assume we have our int readFromBase(int base,char** string, int stringLength) elegant method defined in there*/
typedef int (*readFrombaseFunc)(int, char**, int);
typedef struct (readFromBaseFunc func,int base} converter;
converter[17] converters={
{null,null},
{null,null},
{&readFromBase,2},
{&readFromBase,3},
{&readFromBase,4},
{&readFromBase,5},
{&readFromBase,6},
{&readFromBase,7},
{&readFromBase,8},
{&readFromBase,9},
{&readFromBase,10},
{&readFromBase,11},
{&readFromBase,12},
{&readFromBase,14},
{&readFromBase,15},
{&readFromBase,16}
};
int convertWithArrays(int fromBase,char**string, int stringLength)
{
converter conv=converters[fromBase];
if(conv.func){
return (*conv.func)(conv.base,string,stringlength);
}else{
errno=1004577;
return -1;
}
}
Function pointers FTW!