Hey all,
Quick C question here. We've been playing with double, triple, even quadruple pointers recently. We though we had a grasp on things until we ran into this problem...
char ***data;
data_generator(&data);
char **temp = data[0];
printf("printing temp[%d]: %s\n",0, temp[0]);
printf("printing temp[%d]: %s\n",1, temp[1]);
dosomething(temp);
int dosomething(char **array) {
printf("printing array[%d]: %s\n",0, array[0]);
printf("printing array[%d]: %s\n",1, array[1]);
......
}
int data_generator(char ****char_data) {
char *command1[2];
char *command2[2];
command1[0] = "right";
command1[1] = "left";
command2[0] = "up";
command2[1] = "down";
char **commandArray[2];
commandArray[0] = command1;
commandArray[1] = command2;
number_of_commands = 2;
if(number_of_commands > 1){
*char_data = commandArray;
}
return number_of_commands - 1;
}
And this prints out...
printing temp[0]: right
printing temp[1]: left
Segmentation fault
Looks like I have some misconceptions about what happens to a pointer while passed through a function. Any thoughts?