xt_romantoi(3)

NAME
xt_romantoi() - Convert Roman numeral string to int

LIBRARY
#include <xtend/stdlib.h>
-lxtend

SYNOPSIS
int     xt_romantoi(const char *string, char **endptr)

ARGUMENTS
string: Pointer to the first character of the Roman numeral
endptr: Address of a pointer variable to receive the end of the string

DESCRIPTION
The xt_romantoi() function converts a string containing a valid Roman numeral to an integer, much like strtol(). It rejects non-normalized values, such as IIIII, XXXXX, or CCCCC, which should be written as V, L, and D, respectively. IIII, XXXX, and CCCC are accepted in place of IV, XL, and CD. Any number of consecutive Ms (1000s) are accepted, since there is no larger digit. Like strtol(), it returns the address of the first character not converted as part of the number. This can be used to verify that the number ended as it should have, perhaps with a '0' byte.

RETURN VALUES
The integer value of the Roman numeral if converted, or 0 if an invalid numeral is detected.

EXAMPLES
char    string[] = "XIV", *end;
int     n;
n = xt_romantoi(string, &end);
if ( *end == '0' )
    printf("%dn", n);
else
    fprintf(stderr, "Error converting %s.n", string);

SEE ALSO
strtol(3)