Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cannot convert from 'char' to 'const char *

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
US
I'm using VisualC++ 4.0.

I'm having a hard time trying to write an array to a list.
I get a "cannot convert parameter 2 from 'char' to 'const char *" error when I try to compile it.

Here's the declaration of the array:
Code:
char	bconf[MAXBND+1];	/* Bond CONFormation: ' ',c,t,C,T,E,Z */

Here's how I'm trying to put it in a list. The list gets passed to a different application later:

Code:
			char CFbconf[1000];//bconf[MAXBND + 1]



			for (i = 0 ; i <= MAXBND + 1 ; i++) {

				if (strlen(CFbconf) > 1) {
					strcat(CFbconf,",");	
				}
				
				strcat(CFbconf,bconf[i]);
			

		
			}
 
Try this:

Code:
     char CFbconf[1000];//bconf[MAXBND + 1]
        for (i = 0 ; i <= MAXBND + 1 ; i++)
        {
           if (strlen(CFbconf) > 1)
           {
              strcat(CFbconf,",");    
           }
           strcat(CFbconf, (const char*) bconf[i]);
        }

Hope this works for you.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
If that works, you can also do the same thing without the cast like this:
Code:
strcat( CFbconf, bconf + i );
 
It works. Tried it out. But I like cpjust's way. It is a little cleaner. Less bulky.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
It's not only cleaner: it's a right way because of bconf is a char, not a pointer to char. Type of bconf (in expression) is pointer to char, so bconf+1 is a pointer to i-th element of this array (pointer arithmetics).

But if your strange (undeclared here) bconf pointer refers to the same array CFbconf, you will have troubles (overlapped strings in strcat == crash sooner or later;)...
 
Thanks everyone for your help. Slowly getting the hang of C++ programming, but a long way to go.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top