title: Int array to store large numbers (over 20 digits)
body: <p>I have an assignment that requires me to first set up integer arrays to store arbitrarily large numbers. By using each element of an int array, I can hold one digit per element because int variable types are 32 bits and can only reach up to about 2 billion before failing. I know that there are other libraries using BigInt but I wanted to make my own arrays instead.</p>
  
  <p>I tested my code out, but it doesn't seem to be accepting values past 9 digits until it starts to fail. </p>
  
  <pre><code>int * toArray(int, int);
  int main()
  {
      int n, *res, counter, i;
      printf("Input: ");
      scanf("%d", &amp;n);
      while(n&gt;0){
           n/=10;
           counter++;
      }
      res = toArray(n, counter);
      for(i=1;i&lt;=counter;i++){
           printf("%d", *(res)+i);
      }
      printf("\n");
  }   
  
  int * toArray(int n, int counter)
  {
      int i;
      int *numberArray = malloc(sizeof(int) * counter);
      for(i=0; i&lt; counter; i++)
      {   
           numberArray[i] = n % 10;
      }
      return numberArray;
  }
  </code></pre>
  
  <p>I want to be able to accept close to twenty digits at the very least. I know this can be done with int arrays, although char arrays (or strings) are also a possibility. But I wanted to use int arrays instead. Any help in understanding why it fails around 9 digits and suggestions for going past that would be very much appreciated. Thank you.</p>