During initiation of char** map
I print the values stored.
When I then pass that pointer to a function, and print the values, the output is behaving weirdly.
If I don't print during the creation another, also not expected, behaviour occurs. What is going on?
void main(){
char ** map = (char **) malloc(24);
int i;
for(i = 0; i < 24; i++){
map[i] = (char *) malloc (sizeof(char));
*map[i] = i;
printf("%d\n", *map[i]);
}
display_map(map);
}
void display_map(char **m){
int i;
char bit;
printf("\n");
for(i = 0; i < 24 ; i++ ){
bit = *m[i];
printf("%d\n", bit);
}
}
output:
0
1
2
3
.
.
23
48 //expected 0
1
2
3
.
.
23
If I however remove the print statement when I create char** map
I get this output from display_map
output:
32 //expected 0
-96 //expected 1
32 //expected 2
-96 //expected 3
32 //expected 4
5
6
7
8
.
.
23
This is such a mystery to me.