CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Int8 to Roman Numbers (string) function.

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Redpic



Joined: 18 Dec 2005
Posts: 5
Location: Spain

View user's profile Send private message Visit poster's website

Int8 to Roman Numbers (string) function.
PostPosted: Wed Oct 11, 2006 7:27 am     Reply with quote

First: declarations and function:

Code:

#include <string.h>
...
const int8 Numeros[] = {  1,    4,   5,    9,  10,   40,  50,   90, 100,  400, 500,  900, 1000};
...
//-----------------------------------------------------------------------------

void dec_to_roman(int8 LI, char* ptr){

   int i;
   char tmp[12];
   char* ptmp = (char*) tmp;
   strcpy(ptr,"");
   // transformo  de la tabla Arábiga a la Románica Latinitatis
   // {  1,    4,   5,    9,  10,   40,  50,   90, 100,  400, 500,  900, 1000};
   // { 'I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M'};
   for(i=12;i!=255;i--){
      while(LI >= Numeros[i]){
         LI = LI - Numeros[i];
         Switch(i){
            case 0:
               strcpy(ptmp,"I\0");
               break;
            case 1:
               strcpy(ptmp,"IV\0");
               break;
            case 2:
               strcpy(ptmp,"V\0");
               break;
            case 3:
               strcpy(ptmp,"IX\0");
               break;
            case 4:
               strcpy(ptmp,"X\0");
               break;
            case 5:
               strcpy(ptmp,"XL\0");
               break;
            case 6:
               strcpy(ptmp,"L\0");
               break;
            case 7:
               strcpy(ptmp,"XC\0");
               break;
            case 8:
               strcpy(ptmp,"C\0");
               break;
            case 9:
               strcpy(ptmp,"CD\0");
               break;
            case 10:
               strcpy(ptmp,"D\0");
               break;
            case 11:
               strcpy(ptmp,"CM\0");
               break;
            case 12:
               strcpy(ptmp,"M\0");
               break;
         }
         ptr=strcat(ptr,ptmp);
      }
   }
}
//-----------------------------------------------------------------------------


Second, a use example:

Code:

int8  H=128;
char H_in_RomanusNumericum[12];
...
dec_to_roman(H, (char*) H_in_RomanusNumericum);
printf("%s",H_in_RomanusNumericum);
...


Now H_in_RomanusNumericum is equal to "CXXVIII\0"

A curiosous example: The Pic Roman Clock


Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group