Thread: Clearing array values

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    8

    Clearing array values

    How do you clear array values (or the entire array) so they're empty?

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    If you're talking about an setting an array of integers so that each element equals 0...then you could use a For Loop, going from 0 to (N - 1), where N is the number of elements, and within the For Loop you can set Element[N] = 0.

    What do you mean by empty?
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    WinXP
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    8
    Empty as in no value, it's for a char and an int array, so I can write over it with a smaller string, but not have the end of the old one print out.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You can use memset for char or int arrays, but if you're using C++ you should be using strings or vectors which have clear() methods.

  5. #5
    Let's do some coding! Welshy's Avatar
    Join Date
    Mar 2005
    Location
    Staffordshire University, UK
    Posts
    168
    would setting all of their values to 0 not be good enough?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-19-2008, 02:36 PM
  2. can't assign proper values to an array of string
    By Duo in forum C Programming
    Replies: 1
    Last Post: 04-04-2005, 06:30 AM
  3. Checking maximum values for dynamic array...
    By AssistMe in forum C Programming
    Replies: 1
    Last Post: 03-21-2005, 12:39 AM
  4. accessing array of structs values
    By WaterNut in forum C++ Programming
    Replies: 12
    Last Post: 07-08-2004, 08:47 PM
  5. Duplicate values in Array
    By TONYMX3 in forum C++ Programming
    Replies: 2
    Last Post: 01-30-2002, 03:57 PM