1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

cannot convert parameter 1 from 'char' to 'const char *'

Discussion in 'C' started by sntnknd, Oct 11, 2007.

  1. sntnknd

    sntnknd New Member

    Joined:
    Oct 11, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Dear Experts,

    I am stuck up with a piece of code, which I am not able to break. Could you kindly help me out.

    Situation:
    I am trying to perform a string comparison between 2 variables, one defined as const TCHAR * and other defined as CS_CHAR, inside an Embedded SQL program in C++. My relevant code snippet is as below:

    Code:
    short CSQLBox::fnTest(const TCHAR *varInput)
    {
      CS_CHAR szExtract;
      
      //szExtract variable is populated by Embedded SQL query
      ....
    
      //Do string comparison
      if(strcmp(szExtract, varInput)==0)
      {
        ...
      }
    }
    
    When I try to compile this code, the strcmp step is throwing an error "cannot convert parameter 1 from 'char' to 'const char *'".

    I have tried typecasting parameter 1 as:
    Code:
    if(strcmp((const char*)szExtract, varInput)==0)
    
    This way, the code compiles, but fails in runtime with unhandled exception error. I am unable to understand how to solve this issue.

    Could anyone kindly offer me some suggestions.

    cheers,
    sanK
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Perhaps you should tell us what a CS_CHAR is. I'm not up to Googling it. Since you're using it, you should know.
     
  3. sntnknd

    sntnknd New Member

    Joined:
    Oct 11, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello DaWei,

    My code snippet belongs to an Embedded SQL file in C++. CS_CHAR is a character datatype used in Embedded SQL with Sybase and is declared within a EXEC SQL block. The actual code goes like this:

    Code:
    short CSQLBox::fnTest(const TCHAR *varInput)
    {
      exec sql begin declare section;
      CS_CHAR szExtract[10];
      exec sql end declare section;
        
      szExtract[0] = _T('\0');
    
      //szExtract array is populated by Embedded SQL query
      ....
    
      //Do string comparison
      for( int j=0; j<5; j++)
      {
          if(strcmp(szExtract, varInput)==0)
          {
             ...
          }
      }
    }
    
    cheers,
    sanK
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Your first example has "CS_CHAR szExtract;"

    Your second example has "CS_CHAR szExtract [10];"

    That's a fundamental difference. The first is a char, the second is a char*. You cannot reconcile that with a cast. Make sure you declare an array of char, not just one char.
     

Share This Page