Answer the question
In order to leave comments, you need to log in
How to access elements in an array of strings in C?
Good day! The question is:
Given: an array of strings, let's say
char str[3][6]=
{
" one",
" two",
" three"
};
Answer the question
In order to leave comments, you need to log in
Well, firstly, for the letter t, you need str[1][1] - you have spaces at the beginning there.
Secondly, it doesn't seem to compile at all - you have a string length of 6 characters + an end character - so the array needs str[3][7]
To print the letter 't' you need to access the second character of the second line ( str[1][1]
- will work as you would expect). Because in your code in the lines the first characters are spaces.
It looks like you've pasted an edited example, because it won't even compile - there's not enough room for the third line. " three" is 6 characters, plus a terminating '\0' when as an array only 6 long. This would be a compilation error.
Give a complete example of what you want from it, and what it outputs.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question