-
array update
in my main function i have an array of pointers (the last few contain NULL), I send it to a function and some of those NULL bytes now point to data in the HEAP memory.
How can i update my array in the main.
function is passed *stuff[], it cam hold MAXLEN pointers, so i recreate a char *n[MAXLEN] but when i update n, the array i pass is back to normal when viewed in main().
-
-
when you pass an array, it sends a reference of the first memory location of the array sent. not sure where the problem is, post the function
-
in the main there is char * txt[20]
some pointers point to new strings some to NULL
I pass this to a function that copies it, pointing to the same memory locations, in the function when i update the newly created array's null pointers that used to point to null but now to a new string the original's string(main's) isn't updated because the txt[x] is still null but the function's txt[x] points to a new string.
how can i solve this ?
-
are the arrays in the function created with new?
-
-
post or attach the code, i don't see why it's doing what you say
-
the array in the main continues to point to null because you are only updating the pointer array in the function with the new strings, That happens because at the time you duplicate it they are the same, but adding strings only adds them to the function's pointer array.