title: Need help reading from a file in C
body: <p>I have been looking around for a solution but cannot seem to find a solution to my question so I will ask it. I am working in C and am reading in a .txt and taking all the values and storing them in an array then doing various tasks with them. Now my problem is that no matter what I do I cannot get file pointer I create to point to the file for some reason. I have done this for projects in the past and have compared my code then to the current one and cannot see the issue. The filename needs to be read in from the command line as well. I think there is something wrong with what I'm passing through the command line but am not sure. I have stepped through and the filename is being passed correctly but when it tries to open I get a null pointer so there is just something I'm missing.</p>
  
  <p>The text file will contain a series of numbers, the first number will be the number of numbers in the file after that first number. (So if the number is 10 then there will be ten numbers after 10 is read in) after that first number the remaining numbers will be 0-9 in a random order.  </p>
  
  <p>Below is my current chunk of code only involving reading of the file and storing its data. (I already know the array will be of size 10 which is why the array is declared with that size.)</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
   char* filename = "numbers.txt";
   int arr[10];
   int numElem;
   int indexDesired = 0;
  
  FILE *fp;
  fp = fopen(filename, "r"); // open file begin reading
  if (!fp) 
  {
      printf("The required file parameter name is missing\n");
      system("pause");
      exit(EXIT_FAILURE);
  }
  else
  {
      fscanf(fp, "%d", &amp;numElem); //scans for the first value which will tell the number of values to be stored in the array
  
      int i = 0;
      int num;
      while (i &lt;= numElem) //scans through and gets the all the values and stores them in the array.
      {
          fscanf(fp, "%d", &amp;num);
          arr[i] = num;
          i++;
      }
      fclose(fp);
   }
  }
  </code></pre>
  
  <p>***note: My sort and swap method work perfectly so I have omitted them from the code as the error happens before they are even called. </p>