int main(int argc, char **argv) { int add = 1; char *result = malloc(100); int c; int index; // Parse flags while ((c = getopt(argc, argv, "s:")) != -1) { switch (c) { case 's': add = 0; break; default: printInfo(); return 0; } } // Insure that we have the correct u if (argc < 2) { printInfo(); return 0; } index = optind; if (add) { for (index = optind; index < argc; index++) { strcpy(result, add_roman(result, argv[index])); } } else { // We're doing subtraction so grab the 3rd arg as minuend and subtract the rest. strcpy(result, argv[2]); for (; index < argc; index++) { strcpy(result, subtract_roman(result, argv[index])); } } printf(" SVMMA: %s\n", result); free(result); return 0; }
int main(int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, "Usage %s number\n", argv[0]); exit(1); } char *endptr; long long int num = strtoll(argv[1], &endptr, 10); if (*endptr) { fprintf(stderr, "Conversion error, non-convertable part: %s\n", endptr); exit(1); } if (num > 3999 || num < 1) { fprintf(stderr, "Unable to convert the number %lld\n", num); exit(1); } int carry = 0; GList *list = NULL; while (num) { int digit = (int) num % 10; if (add_roman(&list, digit, carry)) { fprintf(stderr, "Error occurred while converting number\n"); g_list_free(list); exit(1); } num = num / 10; carry += 1; } gchar *output = NULL; g_list_foreach(list, (GFunc) each_do, &output); g_print("%s\n", output); g_list_free(list); g_free(output); return 0; }