Array of character

I just want to ask. I have

Val1="123ee"
Val2="a2345"
Val3="ad4555"
Val4="76a"

How i'm i going to assign:

char_Val1[0]= '123ee'
char_Val1[1]= 'a2345'
char_Val1[2]= 'ad4555'
char_Val1[3]= '76a'

Thanks
I'm not quite sure what you're asking. Val1 through Val4, are those string objects? Are you trying to assign those strings to elements in a character array?
yes
First of all i am going to assume that val1, val2.... are string objects, in which case you can initialize them with a cstring like so:
string val1 = "123ee";
That basically acts as a normal cstring, like a pointer to a multitude of characters. So, when you try to say
val1[0] = '123ee';
it doesn't work because it expects a single charcter i.e. 'a'.
You could try:
1
2
3
4
5
6
7
8
9
string values[4];
string val1 = "123ee",
val2 = "a2345",
val3 = "ad4555",
val4 = "76a";
values[0] = val1;
values[1] = val2;
values[2] = val3;
values[3] = val4; 
Last edited on
LolFactor, string values[4] will create an array of 4 strings from 0-3, not 1-4.
Yes, thank you for reminding me. But that's just splitting hairs. I wanted to prove the basic concept. :)
Topic archived. No new replies allowed.