String Arrays.

Started by
9 comments, last by darookie 17 years, 9 months ago
Can someone point me in the right direction?? Im trying to put some names in an array! myArray[3] myArray[0] = "John" myArray[1] = "Joe" myArray[2] = "Jose" myArray[3] = "Jill" printf("%s", myArray[2]) output: Jose press any key to continue... ********* (whatever! you know) Ive been looking around but cant find anything on it im gonna keep looking though. thx
Advertisement
Which programming language are you using?
What is teh question?
c++
The C++ equivalent of the (presumably pseudo-) code that you posted might look something like this:
std::vector<std::string> myArray(4);myArray[0] = "John";myArray[1] = "Joe";myArray[2] = "Jose";myArray[3] = "Jill";std::cout << myArray[2] << std::endl;
If any of this looks unfamiliar, just ask.
I am just guessing here, but won't this work?

char myArray[3][20];
myArray[0][]="Name1\0";
myArray[1][]="Name2\0";

Something like that?

Programming=Creating,Your fantasy is the only limit!

Quote:Original post by wildex999
I am just guessing here, but won't this work?

char myArray[3][20];
myArray[0][]="Name1\0";
myArray[1][]="Name2\0";

Something like that?
Perhaps you mean something like this:
char* myArray[2];myArray[0] = "Name1";myArray[1] = "Name2";
In any case, this is more idiomatic for C, whereas the OP specified C++.
god, u make it look so ez, thx that'll work..
hmmm 4 some reason those dont work for me?
Quote:Original post by Bluseed
hmmm 4 some reason those dont work for me?
Post the code that doesn't work, along with whatever errors you're getting.

This topic is closed to new replies.

Advertisement