Example #1
0
int numeralToInteger(char *numeral) {
    int i, len = strlen(numeral);
    int totalForNumeral = 0;
    char thisChar[] = " ";
    char *numeralPtr = numeral + len -1;
    int thisVal;
    int prevVal = 0;

    for (i = len; i > 0; i--) {
        memcpy(thisChar, numeralPtr--, sizeof(int));
        thisVal = charToInteger(thisChar);
        if (thisVal < prevVal) {
            totalForNumeral -= thisVal;
        }
        else {
            totalForNumeral += thisVal;
        }
        prevVal = thisVal;
    }
    return totalForNumeral;
}
Example #2
0
int sumOfDigit(char num[], int length) {
    int i;
    int sum = 0;
    for (i = 0; i < length; i++) sum += charToInteger(num[i]);
    return sum;
} // end sumOfDigit