Author Topic: resetting an array to 0? - c programming  (Read 1308 times)

Offline docnascar

  • Sr. Member
  • ****
  • Posts: 465
resetting an array to 0? - c programming
« on: April 04, 2011, 11:13:31 AM »
If I have an array that starts at 0.
Code: [Select]
   int table[4][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};

Then my program fills the array up with integers.

I ask the user if they would like the program to run again, but I want the array to start at all 0's again. How do re-declare/reset it to 0?

Its not as easy as:
table=0;

I tried:
Code: [Select]
table[i][j]=0;

but no luck (probably because i have to send it through a loop to increment i and j I think.)...


« Last Edit: April 04, 2011, 11:21:12 AM by docnascar »
My main PCLINUXOS PC:
KDE Mini
AMD FX-6300 (3.5G / 6 core)
MSI 970A-G46 AM3+ MOBO
G.SKILL Sniper Series 8GB (2 x 4GB) 1866 (PC3 14900)
ECS GeForce GT 440 (Fermi) 512MB 128-bit GDDR5
Seagate Barracuda ST1000DM003 1TB 7200 RPM SATA
SAMSUNG DVD Burner SATA Model SH-224BB
POWERUP PU-550 (550W) p

Offline docnascar

  • Sr. Member
  • ****
  • Posts: 465
Re: resetting an array to 0? - c programming
« Reply #1 on: April 04, 2011, 11:29:19 AM »
Quote
but no luck (probably because i have to send it through a loop to increment i and j I think.)...

I answered my own question....  ;D


I did this and it works...

But if there is a one liner, please tell me.

Code: [Select]
       //reset table to 0
        for (i=0;i<=3;i++)
        {
            for (j=0;j<=3;j++)
            table[i][j]=0;
        }
« Last Edit: April 04, 2011, 11:53:56 AM by docnascar »
My main PCLINUXOS PC:
KDE Mini
AMD FX-6300 (3.5G / 6 core)
MSI 970A-G46 AM3+ MOBO
G.SKILL Sniper Series 8GB (2 x 4GB) 1866 (PC3 14900)
ECS GeForce GT 440 (Fermi) 512MB 128-bit GDDR5
Seagate Barracuda ST1000DM003 1TB 7200 RPM SATA
SAMSUNG DVD Burner SATA Model SH-224BB
POWERUP PU-550 (550W) p