L
L
luckypunch2021-07-21 13:33:00
C++ / C#
luckypunch, 2021-07-21 13:33:00

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"
};

How in the program to address the second line to the first character? Like str[1][0]? It is necessary that the letter t be displayed.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2021-07-21
@GavriKos

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]

W
Wataru, 2021-07-21
@wataru

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.

Z
zxmd, 2014-01-15
@zxmd

What does TinyMCE itself generate when wrapping is selected, what HTML code?
And check if something overlaps float for img from the outside.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question