Hi i m quite new to this forum and C programming and i have encountered a problem which maybe you guys can help me with i ll decribe it below;
I made a library which in it i declared an array of this sort
char* tempArray[];
this array is totally dynamic and works with malloc and realloc and has been tested with valgrind and works properly. then in the library lets say i have a function named myFunction which will pass a reference to the int main() program which makes use of this library which will pass the reference to the memory allocated to this dynamic array what i have declared is something like this.
int myFunction(char **Result){
....
Result = tempArray;
return 0;
}
Then in my main program which i build to test the library i declared another global variable which will hold the array which has the same declaration as the one above
char* Array[];
and the main program is something similar to this
int main(void){
counter = 0;
if (myfunction(Array) != -1){
while(*(Array + counter) != NULL){
print data;
}
exit(0);
}
for some reason i always get a segmentation fault and the data that is printed seems to be corrupted character what i am suspecting is that i am passing by reference incorrectly any tips will be greatly appreciative!
I made a library which in it i declared an array of this sort
char* tempArray[];
this array is totally dynamic and works with malloc and realloc and has been tested with valgrind and works properly. then in the library lets say i have a function named myFunction which will pass a reference to the int main() program which makes use of this library which will pass the reference to the memory allocated to this dynamic array what i have declared is something like this.
int myFunction(char **Result){
....
Result = tempArray;
return 0;
}
Then in my main program which i build to test the library i declared another global variable which will hold the array which has the same declaration as the one above
char* Array[];
and the main program is something similar to this
int main(void){
counter = 0;
if (myfunction(Array) != -1){
while(*(Array + counter) != NULL){
print data;
}
exit(0);
}
for some reason i always get a segmentation fault and the data that is printed seems to be corrupted character what i am suspecting is that i am passing by reference incorrectly any tips will be greatly appreciative!