Here you go...
the program for converting the integers to roman
numerals using files in the c language from 1-5000 range
Find below the portable C source code for a program that will print
all roman numerals from 0 to 5000. Changing the code so it starts
with 1 is left as an exercise.
[snips]
You're welcome.
Here comes the code...
/*
* runum.c
*
* Copyright (c) 2008, John J. Smith
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose except in homework assignments
* is hereby granted without fee, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation.
*
*/
/*
* Requirements:
*
* the program for converting the integers to roman
* numerals using file(s) in the c language from 1-5000 range
*
*/
#include <stdio.h>
#include <string.h>
/*
* the biggest foobarfoobar that foofoobarbar will accept
*/
#define MAX_FOOBARFOOBAR 5000
#define M 1000
#define D 500
#define C 100
#define L 50
#define X 10
#define V 5
#define I 1
#define N 0
/*
* struct: foofoofoofoo
*
* purpose: map foofoofoobar values to their corresponding
* foofoobarfoo values
*
*/
#define M1(a) { #a , (a) }
#define M2(a,b) { #a #b , (b)-(a) }
static struct {
char *foofoofoobar;
int foofoobarfoo;
} foofoofoofoo[] = {
M1(M),M2(C,M),M1(D),M2(C,D),M1(C),M2(X,C),M1(L),
M2(X,L),M1(X),M2(I,X),M1(V),M2(I,V),M1(I),M1(N),
};
#define N_FOOFOOFOOFOO \
((sizeof foofoofoofoo) / (sizeof foofoofoofoo[0]))
#undef M1
#undef M2
static int ConstraintFailed(void) { return -1; }
/*
* function: foofoobarbar
*
* purpose: convert a foobarfoobar value to foobarbarfoo
*
* parameters:
* foobarfoobar: value to be converted
* foobarbarfoo: buffer that receives the converted foobarfoobar
*
* notes:
* it is the callers responsiblility that foobarbarfoo is
* sufficiently large
*/
static int foofoobarbar(int foobarfoobar, char *foobarbarfoo)
{
int barfoobarfoo = 0;
size_t barbarfoofoo;
char *foobarbarbar;
if(foobarfoobar < 0 || foobarfoobar > MAX_FOOBARFOOBAR) {
barfoobarfoo = ConstraintFailed();
strcpy(foobarbarfoo, "ERROR!"); goto barfoobarbar;
}
else if(foobarfoobar == 0) {
strcpy(foobarbarfoo, "N"); goto barfoobarbar;
}
for(foobarbarbar = foobarbarfoo, *foobarbarbar = 0, barbarfoofoo = 0;
barbarfoofoo < N_FOOFOOFOOFOO-1; barbarfoofoo++) {
while(foobarfoobar >= foofoofoofoo[barbarfoofoo].foofoobarfoo) {
char *barfoofoofoo = foofoofoofoo[barbarfoofoo].foofoofoobar;
size_t barfoofoobar = strlen(barfoofoofoo);
memcpy(foobarbarbar, barfoofoofoo, barfoofoobar);
foobarbarbar += barfoofoobar;
foobarfoobar -= foofoofoofoo[barbarfoofoo].foofoobarfoo;
}
}
*foobarbarbar = '\0';
barfoobarbar:
return barfoobarfoo;
}
/*
* function: foobarfoofoo
*
* purpose: as per spec, use file foobarfoobar
*
* parameters: (none)
*/
static int foobarfoofoo(void)
{
FILE *foobarfoobar;
printf("Using file... ");
if((foobarfoobar = tmpfile()) != NULL) {
printf("success!!!\n");
fclose(foobarfoobar);
return 0;
} else {
printf("failed.\n");
return 1;
}
}
/*
* function: main
*
* purpose: program's entry point
* invokes foofoobarbar() MAX_FOOBARFOOBAR times
*/
int main(void)
{
int foobarfoobar;
char foobarbarfoo[64];
printf("John's Table of Roman Numerals\n"
"Copyright (c) MMVIII, John J. Smith\n\n");
foobarfoofoo();
printf("\n"
" arabic | roman\n"
"--------+----------------------\n");
for(foobarfoobar = 0;
foobarfoobar <= MAX_FOOBARFOOBAR;
foobarfoobar++) {
foofoobarbar(foobarfoobar, foobarbarfoo);
printf(" %5d | %s\n", foobarfoobar, foobarbarfoo);
}
return 0;
}
/* end ronum.c */