title: Using calloc in C to initialize int array, but not receiving zeroed out buffer
body: <p>I'm working on solving a programming praxis problem, and am going back to C for kicks to brush up. Anyway, I'm having bugs with an array I'm getting via calloc. The array I'm getting back isn't being initialized to zero. Here's an excerpt of my code, along with the output it's producing. I'm afraid I might just be missing something painfully obvious or idiosyncratic.</p>
  
  <pre><code>int * check_digits;
      // For loop iterating over all numbers with fangsize digits
      for (int i = smallest_fang; i &lt; largest_fang; i++) {
  
          char fang1_word[N];
          sprintf(fang1_word, "%d", i);
  
          for (int j = i; j &lt; largest_fang; j++) {
  
              int dracula;
              char dracula_word[N];
              char fang2_word[N];
  
              check_digits = (int *) calloc((size_t) N, (size_t) sizeof(int));
              printf("HELLO\n");
              for (int arg = 0; arg &lt; 10; arg++) {
                  printf("%d\n", check_digits[arg]);
              }
              printf("\n");
  
              // Verify they both aren't divisible by ten.
              if (((i % 10) == 0) &amp;&amp; ((j % 10) == 0)) { 
                  free(check_digits);
                  continue;   
              }
  
  
              // Calculate potential vampire
              dracula = i * j;
              printf("Here, I is %d and J is %d.\n", i, j);
              printf("The potential vampire is %d\n", dracula);
  
              // Verify potential vampire has enough digits
              sprintf(dracula_word, "%d", dracula);
              sprintf(fang2_word, "%d", j);
  
              printf("Lenth of dracula word is %ld\n", strlen(dracula_word));
              if ((int) strlen(dracula_word) != N) {
                  printf("Wasn't long enough.\n");
                  free(check_digits);
                  continue;
              }
  
  
              // Count up all the vampire's digits into check_digits
              for (int k = 0; k &lt; N; k++) {
                  char digit_char;
                  int digit;
  
                  digit_char = dracula_word[k];
                  digit = (int) strtol( (const char *) &amp;digit_char, (char**) NULL, 10);
                  printf("digit is %d\n", digit);
                  check_digits[digit]++;
              }
  
              // Print out check digits
              printf("\nPrinting out check digits.\n");
              for (int k = 0; k &lt; 10; k++) {
                  printf("The digit %d occurs %d times.\n", k, check_digits[k]);
              }
  
              // See if they all match. No need to make sure any value of
              // check_digits is above zero because digits must already add
              // up.
              int failed = 0;
              for (int k = 0; k &lt; N/2; k++) {
                  char digit_char;
                  int digit;
  
                  digit_char = fang1_word[k];
                  digit = (int) strtol( (const char *) &amp;digit_char, (char**) NULL, 10);
  
                  check_digits[digit]--;
                  if (check_digits[digit] &lt; 0) {
                      failed = 1;
                      break;
                  }
  
                  digit_char = fang2_word[k];
                  digit = (int) strtol( (const char *) &amp;digit_char, (char**) NULL, 10);
  
                  check_digits[digit]--;
                  if (check_digits[digit] &lt; 0) {
                      failed = 1;
                      break;
                  }
              }
  
              // Failed at some point during digit check phase
              if (failed) { 
                  free(check_digits);
                  continue;   
              }
  
              // They all seem to match. Print vampire number
              else {
                  printf("Found vampire number: %d * %d = %d\n", i, j, dracula);
              }
          }
  </code></pre>
  
  <p>When I run the code and grep for a known false positive, I get the following lines:</p>
  
  <pre><code>240211-HELLO
  240217-0
  240219-0
  240221-0
  240223-0
  240225-3
  240227-5
  240229-1
  240231-3
  240233-0
  240235-2
  240237-
  240238-Here, I is 21 and J is 58.
  240265:The potential vampire is 1218
  240295-Lenth of dracula word is 4
  240322-digit is 1
  240333-digit is 2
  240344-digit is 1
  240355-digit is 8
  240366-
  240367-Printing out check digits.
  240394-The digit 0 occurs 0 times.
  240422-The digit 1 occurs 2 times.
  240450-The digit 2 occurs 1 times.
  240478-The digit 3 occurs 0 times.
  240506-The digit 4 occurs 3 times.
  240534-The digit 5 occurs 5 times.
  240562-The digit 6 occurs 1 times.
  240590-The digit 7 occurs 3 times.
  240618-The digit 8 occurs 1 times.
  240646-The digit 9 occurs 2 times.
  240674:Found vampire number: 21 * 58 = 1218
  </code></pre>
  
  <p>Essentially, right after calloc returns a memory buffer, I print it out, and see that's it not clear, resulting in problems later.</p>