Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   cannot convert parameter 1 from 'char' to 'const char *' (http://www.go4expert.com/forums/convert-parameter-1-char-const-char-t6786/)

sntnknd 11Oct2007 21:53

cannot convert parameter 1 from 'char' to 'const char *'
 
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

DaWei 12Oct2007 01:52

Re: cannot convert parameter 1 from 'char' to 'const char *'
 
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.

sntnknd 12Oct2007 14:01

Re: cannot convert parameter 1 from 'char' to 'const char *'
 
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

DaWei 12Oct2007 17:29

Re: cannot convert parameter 1 from 'char' to 'const char *'
 
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.


All times are GMT +5.5. The time now is 06:10.