I'm new to c, and I don't yet understand well enough array structures. I've been struggling for the past hour with finding a way to get nth character of the kth string within an array, and I still don't get it. I have no idea why it shows me everything beyond the nth character, when I just want it to show that nth char.
I've checked How do I access an individual character from an array of strings in c? , and I still can't get it to work.
char ch[3][10] = {"Str 1", "Str 2", "Str 3"};
char a[10][10];
for (int i = 0; i < 3; i++)
{
strcpy(a[i], ch[i]);
printf("a[%d]: \"%s\"\n", i, &a[i]);
for (int j = 0; j < 5; j++)
printf("a[%d][%d]: \"%s\"\n", i, j, &a[i][j]);
}
What the output is (nth char + everything beyond):
a[0]: "Str 1"
a[0][0]: "Str 1"
a[0][1]: "tr 1"
a[0][2]: "r 1"
a[0][3]: " 1"
a[0][4]: "1"
a[1]: "Str 2"
a[1][0]: "Str 2"
a[1][1]: "tr 2"
a[1][2]: "r 2"
a[1][3]: " 2"
a[1][4]: "2"
a[2]: "Str 3"
a[2][0]: "Str 3"
a[2][1]: "tr 3"
a[2][2]: "r 3"
a[2][3]: " 3"
a[2][4]: "3"
What I want the output to be (the nth char):
a[0][0]: "S"
a[0][1]: "t"
a[0][2]: "r"
a[0][3]: " "
a[0][4]: "1"
...
...