Dynamic Array of string, which i would like to pass by reference

kng

Joined
Mar 19, 2008
Messages
1
Reaction score
0
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top