Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Queries and Discussion > Programming > C-C++

Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More
 
Bookmarks Thread Tools Search this Thread Display Modes
Old 10-11-2007, 09:53 PM   #1
Newbie Member
 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
sntnknd is on a distinguished road

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
sntnknd is offline   Reply With Quote
Old 10-12-2007, 01:52 AM   #2
Team Leader
 
DaWei's Avatar
 
Join Date: Dec 2006
Location: Texan now in Central NY
Posts: 835
Thanks: 0
Thanked 3 Times in 2 Posts
Rep Power: 4
DaWei is on a distinguished road

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.
__________________
DaWei on Pointers Grumpy on C++ Exceptions
Functionality rules; clarity matters. If you can work a little elegance in there, you're stylin'.
DaWei is offline   Reply With Quote
Old 10-12-2007, 02:01 PM   #3
Newbie Member
 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
sntnknd is on a distinguished road

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
sntnknd is offline   Reply With Quote
Old 10-12-2007, 05:29 PM   #4
Team Leader
 
DaWei's Avatar
 
Join Date: Dec 2006
Location: Texan now in Central NY
Posts: 835
Thanks: 0
Thanked 3 Times in 2 Posts
Rep Power: 4
DaWei is on a distinguished road

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.
__________________
DaWei on Pointers Grumpy on C++ Exceptions
Functionality rules; clarity matters. If you can work a little elegance in there, you're stylin'.
DaWei is offline   Reply With Quote
Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

 

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