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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Blues, how to set words to array elements

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
0
36
US
here is my code
Code:
/* I tried this */
const char wordarray[]={'Sue','Fred','Sally','Jerry'};
/and this */
	wordarray[0]='Sue';
	wordarray[1]='Fred';
	wordarray[2]='Sally';
	wordarray[3]='Jerry';

I just don't have a grasp on arrays and strings
can someone help with the syntax?
need to set up a pointer?

2 error are on each element
warning: character constant too long for its type
warning: overflow in implicit constant conversion

TIA

DougP
 
Your array type is "char." Char takes a single character, while your trying to push in actual strings. you would either need to make the type of wordarray char*, or CString, or the always fun array or char arrays.. wordarray[][].

Also it should be noted that strings need to be encapsulated within double quotes and not single ticks.
 
Not only
Code:
const char* wordarray[] = ...
but double quotes instead of apostrophes in string literals ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top