title: could not stat file - c
body: <p>I need to stat a file to get the size of it. I also need to provide the name of the file as a command line argument. This is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/stat.h&gt;
  
  int main (int argc, char* argv[])
  {
      int N = 300;
      int L = 1000;
      char Nseq[N][L];
  
      FILE *myfile;
      char *token;
      const char s[2] = ",";
      char *line;
      int lenline;
      char filename[100];
      strcpy(filename, "/path/");
      char name[100];
      strcpy(name, argv[1]);
      strcat(filename, name);
      strcat(filename, ".txt");
      printf("%s\n", filename);
  
      int err;
      struct stat st;
      int n = 0;
  
      err = stat(filename,&amp;st);
      if (err &lt; 0) {
          printf("could not stat file %s", filename);
          exit(1);
      }
      lenline = st.st_size + 1;
  
      line = malloc(lenline);
  
      myfile = fopen(filename, "r");
      if (myfile == NULL) {
          printf("could not open file %s", filename);
          exit(1);
      }
  
      while (fgets(line, lenline, myfile) != NULL) {
          token = strtok(line, s);
          while (token != NULL &amp;&amp; n&lt;N) {
              strcpy(Nseq[n], token);
              printf("%s\t%u\n", token, n);
              token = strtok(NULL, s);
              n++;
          }
      }
  
      fclose(myfile);
  
      return 0;
  }
  </code></pre>
  
  <p>The output I get is:</p>
  
  <pre><code>/path/file.txt
  
  could not stat file /path/file.txt
  </code></pre>
  
  <p>Does anyone know why is this happening? 
  how can I fix it?
  thank you!</p>