I have written the following Code which will convert an integer number to a roman..I have a array list of integer number which I pass through a for loop and the return value is individual converted Roman character..
My Issue is when the converted value is returned from the function I want to capture it in another character array one after the other but am failed to do it..
plzzzz Help
void intToRoman(int num[1000],int m)
{
char * roman[100] = {0};
int iTemp,kTemp,toRoman[1000],jTemp;
int reqNum = {0};
for(iTemp = 0;iTemp< m-1;iTemp++)
{
if(num[iTemp] > num[iTemp+1])
{
break;
}
}
int i=0;
//printf("%d",iTemp+1);
for(kTemp=0;kTemp<=iTemp;kTemp++)
{
roman[kTemp] = Number_AsRomanString(num[kTemp]);
//reqNum[kTemp] = num[kTemp];
//when I print here I get the converted values properly
printf("%s",roman[kTemp]);
printf("\n");
}
//when I Re Print here I get redundant Values of the last index
for(int j=0;j<=iTemp;j++)
{
printf("%s",roman[j]);
printf("\n");
}
// ReWritingIntoTheFile(iTemp);
}
char *Number_AsRomanString( int iNumber )
{
struct RomanDigit_t
{
char *m_psString;
int m_iValue;
};
static const RomanDigit_t RomanDigits[]=
{
{"M", 1000},
{"CM", 900},
{"D", 500},
{"CD", 400},
{"C", 100},
{"XC", 90},
{"L", 50},
{"XL", 40},
{"X", 10},
{"IX", 9},
{"V", 5},
{"IV", 4},
{"I", 1},
};
static char sRomanString[20];
sRomanString[0] = '\0';
for (int i=0; iNumber && i<sizeof(RomanDigits)/
sizeof(RomanDigits[0]); i++)
{
while ( RomanDigits[i].m_iValue <= iNumber )
{
strcat( sRomanString, RomanDigits[i].m_psString );
iNumber -= RomanDigits[i].m_iValue;
}
}
return sRomanString;
}