This is a one dimension char array:
Code:
char oneD[numColumns];
which will hold ONE line of text, less than numColumn char's in length, and the all important end of string marker char: '\0'.
This is what you need to hold multiple strings, and it is a two dimension char array:
Code:
char twoD[numRows][numColumns];
In C, you may see this written as:
Code:
char *twoD[numColumns];
Which is not the same thing (it being an array of pointers to one dimension char arrays), Oops! Make that a one dimension array of pointers to char), but in C, these can be used in a similar (not quite the same however), way.
For now, I suggest you concentrate on using the true 2D char array.
Say you had this 2d char array:
Code:
char twoD[3][9] = { { "January"}, {"February"}, {"March"} };
Note how, in a loop I can refer to any one of these strings.
Code:
for(i = 0; i < 3; i++) {
printf("This is the twoD string #%d, at index #%d: %s\n", i+1, i, twoD[i]); //i will be the row number of the 2D array
}
I only want the first subscript of twoD, because that is the row number - the head of the string. I do NOT want the columns, because I'm not printing out the strings, char by char. See what I mean?
Although I'm printing the strings here, I could just as well be reading in the months of the year data, from a file, using fgets(), as mentioned in a previous post of mine for you.
That's as clear as I can make it.