1. ## an unexpected result.

So I have a piece of a program that creates 2D array of of characters of numbers 1 through a previously found number. Earlier in the code the total amount of numbers that needs to be cataloged is set as num_entries. I then do a basic for loop to convert integers into strings and load them into a new array(actually double pointer).

code:
Code:
```int num_entries = gather_num_entries();
char *audio_nums[num_entries];
char tempchar[num_entries][2];

for(i = 0; i < num_entries; i = i + 1)
{
sprintf(tempchar[i], "%d", i);
audio_nums[i] = tempchar[i];
}```
given a num_entries amount of 5 this should replicate this code:
Code:
```char *audio_nums[5] = {
"0",
"1",
"2",
"3",
"4",
"5"
};```
the output is really confusing me, though. It works just fine up until double digit numbers then goes off in its own little direction.

result:
Code:
```1
2
3
4
5
6
7
8
9
101112131415161718
1112131415161718
12131415161718
131415161718
1415161718
15161718
161718
1718
18```

Can any of you spot something I'm missing?

Thanks
-System_159

2. The problem is here:
Code:
`char tempchar[num_entries][2];`
You can't fit "10" in a 2-character array (you need a '1', a '0', and a '/0'). So since %s prints until it sees a null character, it will print out all the 2-digit numbers at once.

3. Hey, that fixed it. Completely forgot about the null thing.

I knew it would be something odd like that. Now to tackle memory!

Thanks a bunch!

4. Originally Posted by System_159
given a num_entries amount of 5 this should replicate this code:
Code:
```char *audio_nums[5] = {
"0",
"1",
"2",
"3",
"4",
"5"
};```
That's [6] items, not [5].

5. remember the first element in an array is numbered '0'

6. staggering insight there i know

7. I think you are trying to say that iMalc is wrong - which would be quite rare, and the post above is not one of those rare cases.

But the number in brackets when declaring variables is the NUMBER OF ELEMENTS you want, which in your case is 6 - the elements are accessed as [0] .. [5].

--
Mats

8. not saying anyone is wrong bud, was not directing any reply to iMalc, i have been to his homepages link...like i am gonna say how wrong is that guy on array elements, haha i think not