Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error...cannot convert parameter

Status
Not open for further replies.

watshamacalit230

Programmer
Joined
Jan 3, 2003
Messages
1
Location
US
my compiler keeps giving me this error...

C:\Program Files\Microsoft Visual Studio\MyProjects\11\1101x01kt.cpp(25) : error C2664: 'english_number' : cannot convert parameter 1 from 'char [81]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

what does that mean?

this program is supposed to write the numbers in english( the way we really say them )...from 0-100...i've done it all but i keep getting this error so i've only posted the first half of my code cuz its so long...

heres my code...

Code:
#include <stdio.h>

char* english_number( char string ) ;
void get_string( char buffer[], int size ) ;

const int LENGTH = 81 ;

void main( void )
{
	char line[ LENGTH ] ;
	int count ;
	
	printf( &quot;Enter a number  :  &quot; ) ;
	get_string( line, LENGTH ) ;

	printf( &quot;English  :  &quot; ) ;

	for( count = 0 ; line[count] != '\0' ; count++ )
/*error here -->*/	printf( &quot;%s &quot;, english_number( line ) ) ;
}

char* english_number( char string )
{
	if ( string >= '0' && string <= '10' )
	{
		if ( string == '0' )
			return ( &quot;zero&quot; ) ;
		else if ( string == '1' )
			return( &quot;one&quot; ) ;
		else if ( string == '2' )
			return( &quot;two&quot; ) ;
		else if ( string == '3' )
			return( &quot;three&quot; ) ;
		else if ( string == '4' )
			return( &quot;four&quot; ) ;
		else if ( string == '5' )
			return( &quot;five&quot; ) ;
		else if ( string == '6' )
			return( &quot;six&quot; ) ;
		else if ( string == '7' )
			return( &quot;seven&quot; ) ;
		else if ( string == '8' )
			return( &quot;eight&quot; ) ;
		else if ( string == '9' )
			return( &quot;nine&quot; ) ;
		else if ( string == '10' )
			return( &quot;ten&quot; ) ;
	}
}

void get_string( char buffer[], int size )
{
 	char character;
 	int j = 0;		

 	do									/* Get a character until newline or 		*/
 	{									/* we run out of characters.				*/
		character = getchar() ;
		buffer[j] = character ;
		++j;
	}
	while ( character != '\n' && j < size ) ;
	
	while ( character != '\n' )			/* Get rid of extra characters.				*/
		character = getchar() ;

	buffer[j - 1] = '\0' ;				/* Replace newline with the null-byte.		*/
}
 
First off all you should #include <string.h>, then you should return the line from get_string() as a const char*. For completeness, return the string from english_number() as a const char* also. The value passed in as a parameter to english_number() is a single character value yet you are testing it like this:[tt]

else if ( string == '10' )[/tt]

The value of a single character cannot be two characters therefore this parameter should also be a string (const char*) and not a character (char). To test the values you will need to use the strcmp() function - hence the need to #include <string.h>

In saying all this, you may be better off taking the user input as a numerical value and then testing that the number entered is within range. Then pass the number as a parameter to english_number() and return the appropriate string.
tellis.gif

programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top