Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Feb 21st, 2005, 4:19 PM   #1
ViZioN
Newbie
 
Join Date: Feb 2005
Posts: 3
Rep Power: 0 ViZioN is on a distinguished road
Returning An Array From a Function

Hey all,

I'm currently writing a calculator program for Uni which takes in 2 Roman Numeral expressions and displays the answer Roman Numerals. The answer is then displayed in Roman Numerals

i.e IX+XV = XXIV

The problem i'm having is trying to return an array from a function. The function takes in the integer answer worked out earlier in the program, and then converts this to roman numerals, saving each character in an array, which is created by the function. I wish to return the array back into the main program but i'm having problems


Sorry if this has been asked before, I tried searching the forums but couldn't find anything that similar .
The code for my sub-routine is as follows:

char convert(int answer)
{
int j=0;
char numeral[20];

	// Calculate M's
   while((answer-1000)>=0)
   {
	answer=answer-1000;
	numeral[j++]='M';
   }

   if(answer>=900)
   {
   numeral[j++]='C';
   numeral[j++]='M';
   answer=answer-900;
   }

   // Calculate D's

	while((answer-500)>=0)
	{
   answer=answer-500;
	numeral[j]='D';
   j++;
   }

   if(answer>=400)
   	{
   	numeral[j++]='C';
   	numeral[j++]='D';
   	answer=answer-400;
   	}

   // Calculate C's

	while((answer-100)>=0)
   {
	answer=answer-100;
	numeral[j++]='C';
   }

   if(answer>=90)
   {
   numeral[j++]='X';
   numeral[j++]='C';
   answer=answer-90;
   }

   //Calcalute L's

while((answer-50)>=0)
   	{
	answer=answer-50;
	numeral[j++]='L';
   }

   if(answer>=40)
   {
   numeral[j++]='X';
   numeral[j++]='L';
   answer=answer-40;
   }

   // Calculate X's

   while((answer-10)>=0)
	{
	answer=answer-10;
	numeral[j++]='X';
   }

   if (answer==9)
   {
   numeral[j++]='I';
   numeral[j++]='X';
   answer=answer-9;
   }

   // Calculate V's

   while((answer-5)>=0)
	{
	answer=answer-5;
	numeral[j++]='V';
   }

   if(answer==4)
   {
   numeral[j++]='I';
   numeral[j++]='V';
   answer=answer-4;
   }

   // Calculate j's

while((answer-1)>=0)
   {
	answer=answer-1;
	numeral[j++]='I';
   }

   numeral[j]  = '\0';
   printf("\n");
   return numeral;
}

I want to return the array numeral so that it can be displayed on screen and the code can be used to convert other numbers.

These are the errors that the compiler is displaying:

Warn : roman.c(207,19)uspicious pointer conversion
Error: roman.c(207,19):Nonportable pointer conversion

Can someone help me out so that i can get my program working properly?

Thanks in advance,

Dave
ViZioN is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:12 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC