# c for roman words

Discussion in 'Programmer's Corner' started by neeer, Feb 16, 2012.

1. ### neeer Thread Starter New Member

Feb 15, 2012
3
0
can anybody help me to do operations on roman numbers using 'c'?
i want to make addition of roman numbers & display it....

Nov 28, 2011
56
11
This sounds like a classroom assignment. And it sounds like you're asking someone to do it for you, since you're not asking a specific question about the problem. Please give it a shot, and show us where you get stuck, for specific help on specific hurdles.

Thanks!

3. ### RiJoRI Well-Known Member

Aug 15, 2007
536
26
I saw code for this many years ago. It's probably still on the Web. Somewheres. It's the kind of thing I look at, say, "Cute!" and keep going.

It's easier if you forgo the subtractive portion of the numerals: use IIII instead of IV.

--Rich

Apr 5, 2008
15,801
2,387
5. ### kubeek AAC Fanatic!

Sep 20, 2005
4,689
806
instead of doing the actual arithmethics on roman numbers, you should write a function that converts roman to a normal number and another that outpus a number in roman numbers, and do the calculation in a standard way.

6. ### spinnaker AAC Fanatic!

Oct 29, 2009
5,074
1,176
The way I would do this is to create two arrays. One array with the character of the Roman Numeral and the other with it's integer value.

Read the first roman character and compare to each value in the first array. Store the index when found. Then use that to look up it's integer value.

Then calculate the total based on rules of roman numerals like if a lesser value precedes a greater value, the number is subtracted. There are other rules too but the array idea should get you started and not upset your instructor too much.

7. ### neeer Thread Starter New Member

Feb 15, 2012
3
0
thanks to all.
And sorry ,i didnt cleared my question....
i have done program to display roman numbers.but while doing operations on that,i am confused how many parameters i should pass?
this is binary oeration.so it is clear that i have to pass two strings to function.but should i pass the length of the strings also or in function i should calculate length?
actually i am at the sea in 'c'...
And i am little bit confused about passing functions...

8. ### spinnaker AAC Fanatic!

Oct 29, 2009
5,074
1,176
That would all depend up to you how you want to code it. C strings typically end in a null or zero byte so you really don't need to pass the length of a string when passing it to a function but it is a good idea to do so to prevent buffer overflow. Basically passing a string where there is no null terminator so your code runs until it happens to hit a null somewhere in memory.

9. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,436
1,626
Traditionally character strings in C are what is called "zero terminated," meaning the last valid character in the string is followed by a character equal to zero. That's just fine and works rather well. If you want to do a belt and suspenders approach you can always check you're not going past a knows max string limit.

To pass a string to a function you just pass a pointer to the string. The function proto would look something like:

char StringThing(char * strA, char * strB);

And to call it you could do:

char buffer Num1[10];
char buffer Num2[10];

[assign something to the two strings here]

StringThing(&Num1, &Num2);