I was working lately with roman numbers converter, but I can't make run my code properly.
What could be the problem?
#include <stdio.h>
#define ROMAN_PLACE(x) r_output[ro_counter++]=roman_numbers[x]
int main(int argc, char *argv[]) {
char roman_numbers[7] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
char r_output[15];
unsigned char places = 0, i = 0, j = 0, ro_counter = 0;
if (argc == 1) goto exit;
while(argv[1][places++]);
if (places < 2 || places > 5) goto exit;
places--;
if (places == 4)
if (4 < (argv[1][0] - 32) && 0 > (argv[1][0] - 32))
for (ro_counter = i = argv[1][0] - 32; i > 0;)
r_output[--i] = roman_numbers[6];
for (i = !!ro_counter; i < places; i++) {
switch (argv[1][i]) {
case '9':
ROMAN_PLACE((places-i-1)*2);
ROMAN_PLACE((places-i)*2);
break;
case '8': case '7': case '6': case '5':
ROMAN_PLACE((places-i-1)*2+1);
for(j = argv[0][i] - 5; j > '0'; j--)
ROMAN_PLACE((places-i-1)*2);
break;
case '4':
ROMAN_PLACE((places-i-1)*2);
ROMAN_PLACE((places-i-1)*2+1);
break;
case '3': case '2': case '1': {
for(j = argv[0][i]; j > '0'; j--)
ROMAN_PLACE((places-i-1)*2);
break;
}
case '0':
break;
}
}
printf(r_output);
printf("\n");
exit:
return 0;
}