hmm... yes actually that's what I want. Because initially I've stored all the fruit's name into a string array and it's used by other function. And somewhere down the whole code, I need to compare character by character of the fruit's name. For example:
1. P A P A Y A
2. P E A C H
I need to compare "P" with "P", since it's the same, then I've to proceed on the second alphabet which is "A" and "E" and so on...
And I don't understand why you said fruits[0][0] will be equal to "P". Could you please explain it further? Sorry I'm just a new learner..
You can imagine an array of string as an array of arrays, or a 2 dimensional array, if for example we have:
-
string fruits[3];
-
fruits[0] = "peach";
-
fruits[1] = "grape";
-
fruits[2] = "kiwi";
-
if you take fruits at position [0][0] you have char 'p', at position [0][1] you have the char 'e', at position fruits[2][2] you have char 'w'.
by looping through the fruits 2d array you can access all the chars.
this:
-
printf("%c", fruits[1][2]);
-
will print the char 'a'.