title: How to get number of elements in file?
body: <p>Right now, I have</p>
  
  <pre><code>int main(int argc, char *argv[]) {
      if (argc != 3) {
          printf("Invalid number of command line parameters, exiting...\n");
          exit(1);
      }
  
      int *numReadings;
      load_readings(argv[1], numReadings);
  
      return 0;
  }
  
      int *load_readings(char fileName[], int *numReadings) {
          FILE *in = NULL;
          in = fopen(fileName, "r");
  
          if (in == NULL) {
              printf("Unable to open a file named \"%s\", exiting...\n", fileName);
              fclose(in);
              exit(4);
          }
  
          printf("%s\n", fileName);
          int size = atoi(fileName);
          printf("Size is %d\n", size);
          int *data = (int *) calloc(size, sizeof(int));
  
          int i;
          for (i = 0; i &lt; size; i++)
              fscanf(in, "%d", (data + i));
          }
      }
  </code></pre>
  
  <p>And When I do size = atoi(fileName) it returns 0. On multiple sites including this one, I've seen people do "atoi(argv[1])" but mine constantly returns 0. My sample.txt file has a bunch of 3-digit numbers separated by spaces. I am under the impression that once I get the size correctly, everything else below it will work.</p>