Question on 2D Arrays

This is a discussion on Question on 2D Arrays within the C++ Programming forums, part of the General Programming Boards category; Hello, After creating a 2D array and setting all the elements to 0 as follows: Code: char 2darray[10][10] = 0 ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    69

    Question on 2D Arrays

    Hello,

    After creating a 2D array and setting all the elements to 0 as follows:

    Code:
     char 2darray[10][10] = 0
    How would one go about resetting the whole thing to contain all 0's again after filling the array up with characters? Thanks.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    one way is loops. If you are doing it several times in the space of the program's code then put the loops in a function and just call the function, passing it the array you want to reset.

  3. #3
    Registered User Elhaz's Avatar
    Join Date
    Sep 2004
    Posts
    32
    Quote Originally Posted by elad
    one way is loops. If you are doing it several times in the space of the program's code then put the loops in a function and just call the function, passing it the array you want to reset.
    Notice elad said loops. When I do it I use two for loops, one nested within the other.

    I recently made a tic-tac-toe game and in the first version I filled the array I used for the board manually (a zillion commas)! What a drag that was. Then I figured out how to use loops. Feeling much better now!

  4. #4
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    Or maybe smaller
    memset(2darray,0,10*10);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Comparing Arrays question
    By taugust7 in forum C++ Programming
    Replies: 36
    Last Post: 04-14-2009, 12:29 PM
  2. Pointers to 2D arrays
    By bertazoid in forum C Programming
    Replies: 16
    Last Post: 02-26-2009, 03:46 PM
  3. Help with 2d Int Arrays
    By Voondebah in forum C Programming
    Replies: 2
    Last Post: 02-25-2009, 10:36 PM
  4. Help with 2d arrays
    By thamiz in forum C Programming
    Replies: 25
    Last Post: 05-25-2008, 05:06 AM
  5. question on multiplying 2D arrays
    By 3kgt in forum C++ Programming
    Replies: 4
    Last Post: 04-23-2003, 08:26 PM

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