title: Array Realloc In C
body: <p>I'm writing a C program. I want to read data from <code>test.txt</code> file. In my (.txt) file is a list of hexadecimal numbers 8-bit such as: 2A 8E 5A. Then I write these numbers to an array <code>A</code>. I have an error when I using Release mode in Visual Studio. Please tell me what's wrong?</p>
  
  <pre><code>int main(int argc, char *argv[]) {
      FILE *FileIn;
      int i, temp;
      int *A, nA = 0;
      A = (int *)realloc(NULL, sizeof(int));
      FileIn = fopen("test.txt", "r");
      // Add frist value to array.
      fscanf(FileIn, "%x", &amp;temp);
      A[0] = temp;
      nA++;
  
      for(i = 0; i &lt; 16; ++i){
          fscanf(FileIn, "%x", &amp;temp);
          addValue(A, &amp;nA, temp);
      }
  
      for (i = 0; i &lt; 16; ++i) {
          printf("A[%d] = %x\n", i, A[i]);
      }
      free(A);
      system("pause");
      return 0;
  }
  
  void addValue(int *A, int *n, int Data)
  {
       A = (int *)realloc(A, (*n+1)*sizeof(int *));
       A[*n] = Data;
       (*n)++;
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/qxcwL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qxcwL.png" alt="enter image description here"></a></p>