Thread: ERROR! cannot convert parameter...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    21

    Exclamation ERROR! cannot convert parameter...

    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( "Enter a number  :  " ) ;
    	get_string( line, LENGTH ) ;
    
    	printf( "English  :  " ) ;
    
    	for( count = 0 ; line[count] != '\0' ; count++ )
    /*error here -->*/	printf( "%s ", english_number( line ) ) ;
    }
    
    char* english_number( char string )
    {
    	if ( string >= '0' && string <= '10' )
    	{
    		if ( string == '0' )
    			return ( "zero" ) ;
    		else if ( string == '1' )
    			return( "one" ) ;
    		else if ( string == '2' )
    			return( "two" ) ;
    		else if ( string == '3' )
    			return( "three" ) ;
    		else if ( string == '4' )
    			return( "four" ) ;
    		else if ( string == '5' )
    			return( "five" ) ;
    		else if ( string == '6' )
    			return( "six" ) ;
    		else if ( string == '7' )
    			return( "seven" ) ;
    		else if ( string == '8' )
    			return( "eight" ) ;
    		else if ( string == '9' )
    			return( "nine" ) ;
    		else if ( string == '10' )
    			return( "ten" ) ;
    	}
    }
    
    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.		*/
    }
    Watshamacalit

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >char* english_number( char string )
    You pass line to this function, but line is an array of char, change the function tag to

    char* english_number( char *string )

    You'll also have to remodel the function since it uses the relational operators which don't work on strings.

    >void main( void )
    main returns an int, anything else is wrong.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    21

    thanks for your help

    but why is there a black dot on my posts?
    Watshamacalit

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    29
    Code:
    #include <stdio.h>
    
    char english_number( char *string ) ;
    void get_string( char buffer[], int size ) ;
    
    const int LENGTH = 81 ;
    
    int main( void )
    {
    	char line[ LENGTH ] ;
    	int count ;
    	
    	printf( "Enter a number  :  " ) ;
    	get_string( line, LENGTH ) ;
    
    	printf( "English  :  " ) ;
    
    	for( count = 0 ; line[count] != '\0' ; count++ )
    /*error here -->*/	printf( "%s ", english_number( line ) ) ;
    }
    
    char english_number( char *string )
    {
    	if ( string >= '0' && string <= '10' )//have to change way they are compared
    	{
    		if ( (strcmpi(string, '0'))!= 0 )
    			return ( "zero" ) ;//cannot return a string like this
    		else if ((strcmpi(string, '1'))!= 0 )
    			return( "one" ) ;//ditto
    		else if ((strcmpi(string, '2'))!= 0 )
    			return( "two" ) ;//ditto
    		else if ((strcmpi(string, '3'))!= 0 )
    			return( "three" ) ;//ditto
    		else if ((strcmpi(string, '4'))!= 0 )
    			return( "four" ) ;//ditto
    		else if ( (strcmpi(string, '5'))!= 0 )
    			return( "five" ) ;//so forth...
    		else if ( (strcmpi(string, '6'))!= 0 )
    			return( "six" ) ;
    		else if ( (strcmpi(string, '7'))!= 0 )
    			return( "seven" ) ;
    		else if ( (strcmpi(string, '8'))!= 0 )
    			return( "eight" ) ;
    		else if ( (strcmpi(string, '9'))!= 0 )
    			return( "nine" ) ;
    		else if ((strcmpi(string, "10"))!= 0 )
    			return( "ten" ) ;
    	}
    }
    
    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.		*/
    }
    Not everything is fixed to how it should be and I purposely did somethings the wrong way and just didn't do others because what fun is it for you to get the code completed and done for you.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    29
    Code:
    #include <stdio.h>
    
    char english_number( char *string ) ;
    void get_string( char buffer[], int size ) ;
    
    const int LENGTH = 81 ;
    
    int main( void )
    {
    	char line[ LENGTH ] ;
    	int count ;
    	
    	printf( "Enter a number  :  " ) ;
    	get_string( line, LENGTH ) ;
    
    	printf( "English  :  " ) ;
    
    	for( count = 0 ; line[count] != '\0' ; count++ )
    /*error here -->*/	printf( "%s ", english_number( line ) ) ;
    }
    
    char english_number( char *string )
    {
    	if ( string >= '0' && string <= '10' )//have to change way they are compared
    	{
    		if ( (strcmpi(string, '0'))!= 0 )
    			return ( "zero" ) ;//cannot return a string like this
    		else if ((strcmpi(string, '1'))!= 0 )
    			return( "one" ) ;//ditto
    		else if ((strcmpi(string, '2'))!= 0 )
    			return( "two" ) ;//ditto
    		else if ((strcmpi(string, '3'))!= 0 )
    			return( "three" ) ;//ditto
    		else if ((strcmpi(string, '4'))!= 0 )
    			return( "four" ) ;//ditto
    		else if ( (strcmpi(string, '5'))!= 0 )
    			return( "five" ) ;//so forth...
    		else if ( (strcmpi(string, '6'))!= 0 )
    			return( "six" ) ;
    		else if ( (strcmpi(string, '7'))!= 0 )
    			return( "seven" ) ;
    		else if ( (strcmpi(string, '8'))!= 0 )
    			return( "eight" ) ;
    		else if ( (strcmpi(string, '9'))!= 0 )
    			return( "nine" ) ;
    		else if ((strcmpi(string, "10"))!= 0 )
    			return( "ten" ) ;
    	}
    }
    
    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.		*/
    }
    I did not fix everything for you and purposely made somethings the wrong way because it wouldn't be to fun for you if I fixed everything

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >but why is there a black dot on my posts?
    The black dot is there to let you know that you've posted to a thread.

    >return ( "zero" ) ;//cannot return a string like this
    Why not?

    >strcmpi(string, '0'))!= 0
    What purpose does using a nonstandard case insensative string comparison serve when case is irrelevant. The last time I checked, digits don't have upper and lower case.

    Wolfpack if you're going to post code, make sure it's at least correct. If you put errors in that code on purpose, please think about why you're here bfore posting again. Also, the // comment is only valid in C99 or C++, most likely you don't have a compiler for the former and the latter is off topic for this forum.
    Code:
    char *english_number( char *string )
    {
      if ( strcmp ( string, "0" ) == 0 )
        return ( "zero" ) ;
      else if ( strcmp ( string, "1" ) == 0 )
        return( "one" ) ;
      else if ( strcmp ( string, "2" ) == 0 )
        return( "two" ) ;
      else if ( strcmp ( string, "3" ) == 0 )
        return( "three" ) ;
      else if ( strcmp ( string, "4" ) == 0 )
        return( "four" ) ;
      else if ( strcmp ( string, "5" ) == 0 )
        return( "five" ) ;
      else if ( strcmp ( string, "6" ) == 0 )
        return( "six" ) ;
      else if ( strcmp ( string, "7" ) == 0 )
        return( "seven" ) ;
      else if ( strcmp ( string, "8" ) == 0 )
        return( "eight" ) ;
      else if ( strcmp ( string, "9" ) == 0 )
        return( "nine" ) ;
      else if ( strcmp ( string, "10" ) == 0 )
        return( "ten" ) ;
      
      return ""; /* No valid comparisoon */
    }
    -Prelude
    My best code is written with the delete key.

  7. #7
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    I cringe at pointers as they are not my friend; however, if a real programmer would be so kind as to correct my usage, then this crud *might* work as a starting point though I'm not sure how you'd tell the difference between 10 and 1 0 in such a string of numbers now that I re-read your topic..

    Code:
    #include <stdio.h>
    #include <malloc.h>
    #include <stdlib.h>
    
    char *toEnglish(char []); // unbounded arrays are cool
    
    int main(void)
    {
      char number[80];
      char *returnedptr;
      int i, length;
    
      printf("Enter a number: ");
      fgets(number, 80, stdin);
    
      for(i=0; number[i] != '\0'; i++)
        length = i;  // cheap knock off for strlen(string)
    
      number[length] = '\0'; // get rid of '\n'
    
      if((returnedptr = (char *) malloc (256)) == NULL)
      {
        printf("Unable to allocate memory for conversion.");
        return -1;
      }
    
      returnedptr = toEnglish(number);
    
      printf("%s", returnedptr);
    
      return 0;
    }
    
    char *toEnglish(char conversion[])
    {
      char digit;
      int count, j, k;
      const char *EnglishArray[11] = { "zero", "one", "two", 
                                       "three", "four",
                                       "five", "six", "seven", 
                                       "eight", "nine",
                                       "invalid" };
      static char strptr[256];
        
      k=0;
    
      for(count = 0; conversion[count] != '\0'; count++)
      {
        digit = conversion[count];
    
        switch(digit)
        {
          case '0': for(j = 0; EnglishArray[0][j] != '\0'; j++)
                       strptr[k++] = EnglishArray[0][j];
                    
                    strptr[k++] = ' ';
    			        
                    break;
    		  
          case '1': for(j = 0; EnglishArray[1][j] != '\0'; j++)
                       strptr[k++] = EnglishArray[1][j];
    					
                    strptr[k++] = ' ';
    			        
                    break;
    		  
          case '2': for(j = 0; EnglishArray[2][j] != '\0'; j++)
                       strptr[k++] = EnglishArray[2][j];
    					
                    strptr[k++] = ' ';
    			        
                    break;
    
    		  
          case '3': for(j = 0; EnglishArray[3][j] != '\0'; j++)
                       strptr[k++] = EnglishArray[3][j];
    					
                    strptr[k++] = ' ';
    			        
                    break;
    
          case '4': for(j = 0; EnglishArray[4][j] != '\0'; j++)
                       strptr[k++] = EnglishArray[4][j];
    					 
                    strptr[k++] = ' ';
    			        
                    break;
    
          case '5': for(j = 0; EnglishArray[5][j] != '\0'; j++)
                       strptr[k++] = EnglishArray[5][j];
    					
                    strptr[k++] = ' ';
    			        
                    break;
    
          case '6': for(j = 0; EnglishArray[6][j] != '\0'; j++)
                       strptr[k++] = EnglishArray[6][j];
    					
                    strptr[k++] = ' ';
    			        
                    break;
    
          case '7': for(j = 0; EnglishArray[7][j] != '\0'; j++)
                    strptr[k++] = EnglishArray[7][j];
    					
                    strptr[k++] = ' ';
    			        
                    break;
    
          case '8': for(j = 0; EnglishArray[8][j] != '\0'; j++)
                       strptr[k++] = EnglishArray[8][j];
    					
                    strptr[k++] = ' ';
    			        
                    break;
    		  
         case '9': for(j = 0; EnglishArray[9][j] != '\0'; j++)
                      strptr[k++] = EnglishArray[9][j];
    					
                   strptr[k++] = ' ';
    			        
                   break;
    		  
         default : for(j = 0; EnglishArray[10][j] != '\0'; j++)
                      strptr[k++] = EnglishArray[10][j];
                   strptr[k++] = ' ';
                   
                   break;
        }; // end switch
    
      } // end for loop
    
      strptr[k] = '\0';
    
      return strptr;
    }
    I rather like arrays though. :P
    Last edited by ronin; 01-03-2003 at 03:15 PM.

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    If you're going to fill the screen with code you might as well cover more than 0-10:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    char *wordbuild ( char *n, int ncomm )
    {
      int i, nleft, len;
      char *p = NULL;
      static char ret[1024];
      
      /* Word lists */
      static char *ones[] = {"one ","two ","three ","four ",
        "five ","six ","seven ","eight ","nine "};
      static char *tens[] = {"ten ","eleven ","twelve ","thirteen ",
        "fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "};
      static char *twenties[] = {"","twenty ","thirty ","forty ",
        "fifty ","sixty ","seventy ","eighty ","ninety "};
      static char *hundreds[] = {
        "hundred ","thousand ","million "};
      
      memset ( ret, '\0', 1024 );
      len = strlen ( n );
      
      for ( i = 0; i < len; i++ ) {
        if ( ( p = strchr ( ( n[i] == ',' ) ? &n[++i] : &n[i], ',' ) ) == NULL )
          p = &n[strlen ( n )];
    
        if ( n[i] == '0' )
          continue;
        
        if ( ( nleft = ( p - &n[i] ) ) != 0 ) {
          if ( nleft == 3 ) {
            strcat ( ret, ones[n[i] - '0' - 1] );
            strcat ( ret, hundreds[0] );
          }
          else if ( nleft == 2 ) {
            if ( n[i] == '1' ) {
              strcat ( ret, tens[n[++i] - '0'] );
              nleft--;
            }
            else
              strcat ( ret, twenties[n[i] - '0' - 1] );
          }
          else
            strcat ( ret, ones[n[i] - '0' - 1] );
        }
        
        if ( nleft == 1 && ncomm != 0 )
          strcat ( ret, hundreds[ncomm--] );
      }
      
      return ret;
    }
    
    char *commaize ( unsigned long n, int *ncomm )
    {
      static char ret[30];
      
      int i = 0;
      char *p = &ret[sizeof(ret)-1];
      
      *p = '\0';
      *ncomm = 0;
      
      do {
        if ( i % 3 == 0 && i != 0 ) {
          *--p = ',';
          ++*ncomm;
        }
        
        *--p = (char)( '0' + n % 10 );
        
        n /= 10;
        
        i++;
      } while ( n != 0 );
      
      return p;
    }
    
    char *stow ( int n, char *buf )
    {
      int i;
      char *p, *ret;
      
      p = commaize ( n, &i );
      ret = wordbuild ( p, i );
      
      if ( buf != NULL ) {
        strcpy ( buf, ret );
        return buf;
      }
      
      return ret;
    }
    
    int main ( void )
    {
      char buf[1024];
      
      printf ( "%s\n", stow ( 123456789, NULL ) );
      printf ( "%s\n", stow ( 12, NULL ) );
      
      stow ( 23, buf );
      printf ( "%s\n", buf );
      
      return 0;
    }


    -Prelude
    My best code is written with the delete key.

  9. #9
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Originally posted by Prelude
    If you're going to fill the screen with code you might as well cover more than 0-10:
    -Prelude
    lol.... well it isn't my program besides, I only picked up a C book last weekend. :P

    A million... that's funny.

    Now that's what I call coding..... let me copy that paste to see what it does...

    [output]one hundred twenty three million four hundred fifty six thousand seven hundred eighty nine
    twelve
    twenty three [/output]

    Could use a comma or something.

    Thanks Prelude.... that code is interesting.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  10. #10
    Registered User
    Join Date
    Nov 2002
    Posts
    29
    Please Prelude take the time to look at the last line of the post that I made.

    Not everything is fixed to how it should be and I purposely did somethings the wrong way and just didn't do others because what fun is it for you to get the code completed and done for you.
    I see no way that he could learn from getting code back that is perfect. I learn on the basis of getting a push from someone else and going back and fixing it myself. Part of programming is to know what is going on and what ways are better than others and the only way that you gain this is through experience which is gained by going back and fixing itself.

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Please Prelude take the time to look at the last line of the post that I made.
    I did not miss that part of your post, but my comments still stand. Someone comes onto these forums looking for an answer to a question that supposedly they've been working on and couldn't figure out. The last thing they want to hear is "I'll make a few inaccurate comments about your code and leave fixing the errors up to you, enjoy!". I find such posts incredibly arrogant and rude.

    >I see no way that he could learn from getting code back that is perfect.
    Perhaps correct and working examples that are explained thoroughly as well as what was wrong with their code to begin with? I see no way that he could learn from being given back the same errors he couldn't fix so that he gets discouraged and quits.

    >I learn on the basis of getting a push from someone else and going back and fixing it myself.
    Not everyone is like you.

    -Prelude
    My best code is written with the delete key.

  12. #12
    Registered User
    Join Date
    Jan 2003
    Posts
    99
    *bows his head to superiority*

    Well I didn't have time to go a bit fancier. I just edited some stuff and I haven't tested it so use at your own discretion but besides why would you be lookin at mine when you got Prelude's up there

    Code:
    #include <stdio.h>
    
    char english_number( char *string ) ;
    void get_string( char buffer[], int size ) ;
    
    const int LENGTH = 81 ;
    
    char *NUMB[11]={"zero","one","two","three",
                    "four","five","six","seven",
                    "eight","nine","ten"};
    
    int main( void )
    {
    	char line[ LENGTH ] ;
    	int count ;
    	
    	printf( "Enter a number  :  " ) ;
    	get_string( line, LENGTH ) ;
    
    	printf( "English  :  " ) ;
    
    	for( count = 0 ; line[count] != '\0' ; count++ )
    /*error here -->*/	printf( "%s ", english_number( line ) ) ;
    }
    
    char english_number( char *string )
    {
    		if ( (strcmp(string, "0"))== 0 )
    			return ( NUMB[0] ) ;
    		else if ((strcmp(string, "1"))== 0 )
    			return( NUMB[1] ) ;
    		else if ((strcmp(string, "2"))== 0 )
    			return( NUMB[2] ) ;
    		else if ((strcmp(string, "3"))== 0 )
    			return( NUMB[3] ) ;
    		else if ((strcmp(string, "4"))== 0 )
    			return( NUMB[4] ) ;
    		else if ( (strcmp(string, "5"))== 0 )
    			return( NUMB[5] ) ;
    		else if ( (strcmp(string, "6"))== 0 )
    			return( NUMB[6] ) ;
    		else if ( (strcmp(string, "7"))== 0 )
    			return( NUMB[7] ) ;
    		else if ( (strcmp(string, "8"))== 0 )
    			return( NUMB[8] ) ;
    		else if ( (strcmp(string, "9"))== 0 )
    			return( NUMB[9] ) ;
    		else if ((strcmp(string, "10"))== 0 )
    			return( NUMB[10] ) ;
    }
    
    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.		*/
    }

  13. #13
    Registered User
    Join Date
    Dec 2002
    Posts
    21

    Thumbs up thanks for your help

    this will help a lot, thanks guys

  14. #14
    Registered User denizengt's Avatar
    Join Date
    Sep 2003
    Posts
    19

    Smile

    Prelude, in your code above could you explain the role of memset?

    Could you also explain the role of *ncomm in commarize and ncomm in word build.

    The commarize code is a little confusing, once I understand that I think I may understand how to do this problem!

  15. #15
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Prelude, in your code above could you explain the role of memset?
    It clears out the contents from previous calls to the function.

    >Could you also explain the role of *ncomm in commarize and ncomm in word build.
    It holds the number of commas. This is how I determined where to print certain qualifiers such as hundred, thousand and million. At the time I wrote this I determined that that approach would be simpler than counting digits.

    On a side note, please don't reply to such old threads. If you have a question to me personally then please contact me via email or preferably by private message.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-08-2008, 06:31 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM