Thread: deleting elements from an array?

  1. #1
    Registered User
    Join Date
    Aug 2009

    deleting elements from an array?

    So i'm writing a small inventory type program, it entails walking around some map and picking up items. For quick prototyping purposes i've created an array with the items in the map. The first field is the name, the second is quantity, and the third is in which zone that item can be found.
    char *wildItems[][3]={{"HP Potion", "1", "1"}, {"Apple", "2", "1"}, {"Apple", "2", "2"}};
    Now after this it becomes just picking up items. I can display it all great, but now my question is after an item is picked up, how can I remove that item from the array instead of just putting some dummy value for the zone?

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    You can't physically remove something from the array. You can only overwrite it with something else.
    If you want to be able to remove something, I would suggest something like linked lists.
    Oh, and you probably would benefit from structs.
    And this might also be informative: Common mistakes and errors - cpwiki (especially strings should be const char*).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Aug 2009
    awesome, thanks! That link was also mad useful.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printing array elements in ascending order
    By galmca in forum C Programming
    Replies: 29
    Last Post: 10-24-2004, 11:24 PM
  2. Problem with assigning value to array elements
    By sagitt13 in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2004, 11:26 AM
  3. reversing elements in array
    By dantestwin in forum C++ Programming
    Replies: 6
    Last Post: 07-08-2004, 08:24 PM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. A simple question about selecting elements in an array
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 10:37 PM