1,105,546 Community Members

convert from 'const char[ 9] to 'char *[]' error

Member Avatar
antra1234
Newbie Poster
1 post since May 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

char *default message[]="hghgghjgh"
char *message=defaultmessage
tis line showing error as
'initializing':cannot convert from 'const char[ 9] to 'char *[]'
can u help me....?

Member Avatar
abhimanipal
Master Poster
746 posts since Dec 2009
Reputation Points: 91 [?]
Q&As Helped to Solve: 104 [?]
Skill Endorsements: 0 [?]
 
0
 

char *default message[]="hghgghjgh"
char *message=defaultmessage
tis line showing error as
'initializing':cannot convert from 'const char[ 9] to 'char *[]'
can u help me....?

Start your own thread for your problems

Member Avatar
Salem
Posting Sage
7,177 posts since Dec 2005
Reputation Points: 5,138 [?]
Q&As Helped to Solve: 970 [?]
Skill Endorsements: 41 [?]
Team Colleague
 
0
 

Well how you fix it depends on what you're trying to achieve in the first place (we can't tell from 2 lines and an error message).

This should work (but is it what you want?)

char  defaultmessage[]="hghgghjgh";
char *message=defaultmessage;
Member Avatar
fazakaspeter
Newbie Poster
1 post since Aug 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I think the actual error is caused by the fact that both *default message (or probably *defaultmessage )is declared as a pointer array and you can't assign (not 100% true, but here is ok) a string. This is why if you have without * it works.

or is there something else you are asking??

Member Avatar
abhimanipal
Master Poster
746 posts since Dec 2009
Reputation Points: 91 [?]
Q&As Helped to Solve: 104 [?]
Skill Endorsements: 0 [?]
 
0
 

I think the actual error is caused by the fact that both *default message (or probably *defaultmessage )is declared as a pointer array
I guess you mean array of pointers

and you can't assign (not 100% true, but here is ok) a string.

Why is it ok here ?

This is why if you have without * it works. or is there something else you are asking??

I think the solution provided by Salem is correct

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article