I'm trying to point a pointer to the middle of an array then loop indexes after and before that certain middle value using an algorithm, the algorithm is working fine, but when I try to loop the first index after the pointed one, my index jumps by 1 number, to be more precise, if we consider our pointer is pointing at index[0], I can use the value of index[0], then it goes to index[1], it thinks that it's empty (although it's not), then goes to index[2] and it can use it again, but then again, it thinks index[3] is empty, and this bug continues like a loop! I have tried everything but no matter what I do, it still skips index[1], I even have the -Wall and -g flags on and gcc doesn't give me any warnings either!
this is the code:
#include <stdio.h>
int main()
{
char *alphabet[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
"m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
char *p_alphabet = alphabet[12];
int i;
for (i = 0; i < 26; i++) {
printf("%d: %c\n", i, p_alphabet[i]);
}
}
and this is the output I get:
0: m
1:
2: n
3:
4: o
5:
6: p
7:
8: q
9:
10: r
11:
12: s
13:
14: t
15:
16: u
17:
18: v
19:
20: w
21:
22: x
23:
24: y
25: