array update

This is a discussion on array update within the C++ Programming forums, part of the General Programming Boards category; in my main function i have an array of pointers (the last few contain NULL), I send it to a ...

  1. #1
    Unregistered
    Guest

    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().

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    post your code
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    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

  4. #4
    Unregistered
    Guest
    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 ?

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    are the arrays in the function created with new?

  6. #6
    Unregistered
    Guest
    yes

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    203
    post or attach the code, i don't see why it's doing what you say

  8. #8
    Something Clever ginoitalo's Avatar
    Join Date
    Dec 2001
    Posts
    187
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 08:25 PM
  2. Polymorphism; Update functions and accessibility
    By CaptainMaxxPow in forum C# Programming
    Replies: 2
    Last Post: 04-23-2009, 09:48 AM
  3. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 11:33 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 08:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21