I am trying to work out the coding for having an array with characters within the array. For example, if I declared a variable of type "int":
int items[5];
I want to put, for instance, the word "milk" at item[0], the word "bread" at item[1] and the word "eggs" at item[2].
I realise I would have to tell the array (variable?) to be of type "char" but it seems that specifying, for example, an array like:
char items[20];
just makes it so that the variable "items" can accept up to 20 characters. I want to know how to make the 20 represent 20 slots or elements or whatever and accept strings of characters, say, 20 characters long for each slot.
Bazzy, how would I declare this "string items[20]"?
I tried to put in string instead of char and string doesn't come up as blue in Visual C++ 2008. Or, could you give me an example of how to use the bidimensional char arrays?
I tried it this way:
char items[20][20]
then later in the program I've got:
cout<<"Enter a first item: ";
cin>>items[0][0]
cout<<"Enter a second item: ";
cin>>items[0][1];
The program terminates incorrectly with this code. Any suggestions?
Thanks.