fork download
  1.  
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. int ratoi(const char *romstr)
  7. {
  8. const numdigits = 8;
  9. // const char digits[numdigits] = "IVXLCDM";
  10. int count[numdigits] = { 0,0,0,0,0,0,0,0 };
  11. const int value[numdigits] = { 0, 1, 5, 10, 50, 100, 500, 1000 };
  12. unsigned char mapper[26] = { 0,0,5,6,0,0,0,0,1,0,0,4,7, 0,0,0,0,0,0,0,0,2,0,3,0,0 };
  13. int retval = 0;
  14.  
  15. int lp;
  16.  
  17. while (*romstr)
  18. {
  19. int mapval = *romstr - 'A';
  20. int mapped = mapper[mapval];
  21. int mappedvalue = value[mapped];
  22.  
  23. retval += value[mapped];
  24. if (mapped < numdigits - 1)
  25. count[mapped + 1] -= 2 * mappedvalue;
  26. if (mapped < numdigits - 2
  27. count[mapped + 2] -= 2 * mappedvalue;
  28. romstr++;
  29. }
  30.  
  31. return retval;
  32. }
  33.  
  34.  
  35. int main(int argc, char **argv)
  36. {
  37.  
  38. char* const input = "MCMXCIX";
  39. printf("ratoi(%s) = %u\n", input , ratoi(input));
  40.  
  41. return 0;
  42. }
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
cc1: warnings being treated as errors
prog.c: In function ‘ratoi’:
prog.c:8: error: type defaults to ‘int’ in declaration of ‘numdigits’
prog.c:10: error: variable-sized object may not be initialized
prog.c:10: error: excess elements in array initializer
prog.c:10: error: (near initialization for ‘count’)
prog.c:10: error: excess elements in array initializer
prog.c:10: error: (near initialization for ‘count’)
prog.c:10: error: excess elements in array initializer
prog.c:10: error: (near initialization for ‘count’)
prog.c:10: error: excess elements in array initializer
prog.c:10: error: (near initialization for ‘count’)
prog.c:10: error: excess elements in array initializer
prog.c:10: error: (near initialization for ‘count’)
prog.c:10: error: excess elements in array initializer
prog.c:10: error: (near initialization for ‘count’)
prog.c:10: error: excess elements in array initializer
prog.c:10: error: (near initialization for ‘count’)
prog.c:10: error: excess elements in array initializer
prog.c:10: error: (near initialization for ‘count’)
prog.c:11: error: variable-sized object may not be initialized
prog.c:11: error: excess elements in array initializer
prog.c:11: error: (near initialization for ‘value’)
prog.c:11: error: excess elements in array initializer
prog.c:11: error: (near initialization for ‘value’)
prog.c:11: error: excess elements in array initializer
prog.c:11: error: (near initialization for ‘value’)
prog.c:11: error: excess elements in array initializer
prog.c:11: error: (near initialization for ‘value’)
prog.c:11: error: excess elements in array initializer
prog.c:11: error: (near initialization for ‘value’)
prog.c:11: error: excess elements in array initializer
prog.c:11: error: (near initialization for ‘value’)
prog.c:11: error: excess elements in array initializer
prog.c:11: error: (near initialization for ‘value’)
prog.c:11: error: excess elements in array initializer
prog.c:11: error: (near initialization for ‘value’)
prog.c:27: error: expected ‘)’ before ‘count’
prog.c:29: error: expected expression before ‘}’ token
prog.c:15: error: unused variable ‘lp’
stdout
Standard output is empty