×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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:

=====
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:
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

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

szExtract is a char, not a null terminated string, which is what strcmp requires.  You can compare the first char in varInput to szExtract, but that's all.  To do what you want, you need to change the data type of szExtract to a null terminated char array, or compare the first char in varInput to szExtract.

Lee

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

(OP)
Hello trollacious,

Thank you for your response. I must say I had tried to be too specific and had missed out to mention that szExtract is an array. The actual piece of code goes like this:

=====
short CSQLBox::fnTest(const TCHAR *varInput)
{
  CS_CHAR szExtract[10];
  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[j], varInput)==0)
  {
    ...
  }
}
=====

And the same error message is shown during compilation. Could you kindly suggest.

cheers,
sanK

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

Please use [code][/code] tags when posting code.

--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

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

You're still trying to compare a single char to a null-terminated string.  If the last char in the array is '\0', then you could try the following, though the rest of your code makes me doubtful that it will work the way you want.

CODE

if(strcmp(&szExtract[j], varInput)==0)

How about explaining in simple English what you're trying to accomplish with that code?

Lee

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

Looks like CS_CHAR is actually a char.  strcmp works on null terminated strings.  If you wish to compare for individual characters, either do them one at a time (1) or stick the character into a 2 byte string with the second byte being a null terminator (2).  szExtract holds the whole string then just compare using szExtract (3)

CODE

// 1
   for ...
   {
      if (szExtract[j] == *varInput) ...
// 2
   for ...
   {
       char szCompare[2];
       szCompare[0] = szExtract[j];
       szCompare[1] = '\0';
       if (strcmp (szCompare, varInput) == 0)...
// 3
// remove the for loop
   if (strcmp (szExtract, varInput) == 0)...

Note that if you are using TCHAR, you should actually be using _tcscmp instead of strcmp.  That way, if you #define UNICODE, you won't hit more problems.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close