• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Help on writing in C

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

r4fo

Member
Joined
Mar 18, 2004
Location
Asuncion - PY
I need to write a program that converts roman numbers to arabic but not numbers (eg. 1, 2, 3, 4,) instead they must be words eg. one, two, three, eleven etc.." any tips???
Thanks
 
I would create a 2 dimensional array. Each row would contain a number, the first column would be the Roman numeral and the second column would contain the English word.

Code:
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))

void convertRomanNumeralToEnglishWord(char *word, const char *roman){
  const char* map[][2] = {
    {"0",   "zero"},
    {"I",   "one"},
    {"II",  "two"},
    {"III", "three"},
    {"IV",  "four"},
    {"V",   "five"},
  };
  int idx;

  for (idx = 0; idx < ARRAY_SIZE(map); idx++){
    if (strcmp(roman, map[idx][0]) == 0){
      break;
    }
  }
  if (idx < ARRAY_SIZE(map)){
    strcpy(word, map[idx][1]);
  } else {
    word[0] = '\0';
  }
}
 
Back