Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site cmu-cs-g.ARPA Path: utzoo!linus!philabs!cmcl2!seismo!rochester!cmu-cs-pt!cmu-cs-g!monta From: monta@cmu-cs-g.ARPA (Peter Monta) Newsgroups: net.sources Subject: rtoi---``roman to integer'' Message-ID: <267@cmu-cs-g.ARPA> Date: Sun, 28-Apr-85 11:45:11 EDT Article-I.D.: cmu-cs-g.267 Posted: Sun Apr 28 11:45:11 1985 Date-Received: Mon, 29-Apr-85 06:31:46 EDT Organization: Carnegie-Mellon University, CS/RI Lines: 37 Here is a C function that converts roman numeral strings to integers. It doesn't complain about syntax errors (I seem to remember my junior-high-school teacher insisting that ``IC'' is wrong, should be ``XCIX''; something like only one ``level'' of subtractive notation permitted). Anyway, if these semantics are wrong, tell me about it. (Thank goodness for positional notation.) Peter Monta monta@cmu-cs-g ..!rocherster!cmu-cs-pt!cmu-cs-g!monta -----------------------------------Cut Here----------------------------------- #include #define max_table 7 static struct { char name; int value } table[max_table] = { {'i',1}, {'v',5}, {'x',10}, {'l',50}, {'c',100}, {'d',500}, {'m',1000} }; int rtoi(s) char s[]; { int i,j,old,new,sum; sum = 0; old = 0; for (i=strlen(s)-1; i>=0; i--) for (j=0; j