Hello Guys, i have this code down here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
void test_func(void *vp1, void *vp2);
int main(int argc, char const *argv[])
{
int size = 2;
char **_char_arr = (char **)malloc(size * sizeof(char *));
_char_arr[0] = (char*)malloc(100 * sizeof(char));
_char_arr[1] = (char*)malloc(100 * sizeof(char));
*(_char_arr + 0) = "hello\0";
*(_char_arr + 1) = "world\0";
printf("arr1 1: %p, arr1 value: %s\n", _char_arr, _char_arr[0]);
printf("arr2 2: %p, arr2 value: %s\n", _char_arr + 1, _char_arr[1]);
test_func(_char_arr, _char_arr + 1);
free(_char_arr);
return 0;
}
void test_func(void *vp1, void *vp2)
{
printf("vp 1: %p, vp1 value%s\n", vp1, (char *)vp1);
printf("vp 2: %p, vp2 value%s\n", vp2, (char *)vp2);
}
|
//////////////////
Here is the output
arr1 1: 0x100200040, arr1 value: hello
arr2 2: 0x100200048, arr2 value: world
vp 1: 0x100200040, vp1 value\251
vp 2: 0x100200048, vp2 value\260
Program ended with exit code: 0
//////////////////
I'm just passing the 2 array to the "test_func" and, as can you see, the pointers of two array is the same, out and inside the function.. but i cant print the value.. inside the function.
Even if i explicit cast to a char pointer.. what is the issue here?
Thank you all for the answare.