Thread: Array Help

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    208

    Array Help

    Ok I made a game which I want to store results of user input in a array and reads it later in the program except I have no idea how many time the user is going to use the game in one sitting so I have no way to make an array to acomidate this problem.

    thanx
    kas2002

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    a few suggestions.

    1. linked list
    2. std::vector
    3. resize and copy your own dynamic array
    4. use a file instead.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    std::vector seems like the best option.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    208

    ummm....

    I have no idea what std::vector is????
    I would use a file but accessing a file many times in like3 4 seconds would be really slow though wouldn't it?

    >>resize and copy your own dynamic array

    is that overly hard? it sounds like my best option because I haven't much experince with linked lists.

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    pretty easy.

    -fill in new pointer with new size
    -memcpy the data from the old array to the new one
    -fill in the new element
    -delete the old array
    -put the new array in the original pointer

    bang! you've resized
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    Registered User
    Join Date
    May 2002
    Posts
    208

    nice

    thanxs all
    Jeff Paddon
    Undergraduate Research Assistant
    Physics Department
    St. Francis Xavier University

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM