how do i initialise my array again in c?

if my array already contains a few values, what is the fastest and most efficient way to delete everything in my table?

i want to do it in my main function, but the array is score[num], where num can be any number but only a total of 100 values. so in this case i cannot use 

for(i = 0; i <= 100; i++) {

    score[i] = 0;

since the 'num' isnt values from 1 to 100

help please!!

3 Answers

Relevance
  • 4 weeks ago
    Best Answer

    const int n = 0; // or any value to set them to

    const int count = 100; // or any count of values

    memset(score, 0, count*sizeof(int)); // all at once

    Or consider SecureZeroMemory.

  • 1 month ago

    int i;

    for(i = 0; i < 100; i++) {

    ... score[i] = 0;

    }

    ... will set every value in array "score" to zero. "i" varies from 0 to 99 inclusive. Use "< 100" NOT "<= 100"

    • VP
      Lv 7
      4 weeks agoReport

      ... You should have used the same number of fingers each time. Listen to 'Brillaint_Moves' -- he's trying to help you out.

  • 1 month ago

    I'm gonna get the one day I'll be getting

Still have questions? Get your answers by asking now.