title: Strcpy clear all file path
body: <p>I am trying to save the names and sizes of files in a directory in this way:</p>
  <p>For the first file everything is fine.
  On the second file it says it can't determine the file path. This is because at the end I clear the &quot;mainPath&quot;, but then when the reassignment takes place the variable &quot;path&quot; is also cleared.</p>
  <pre><code>if ((directory = opendir(path)) != NULL)
  {
      while((d = readdir(directory)) != NULL)
      {
          if(strcmp(d-&gt;d_name, &quot;..&quot;)!=0 &amp;&amp; strcmp(d-&gt;d_name, &quot;.&quot;)!=0)
          {
              strcpy(fileSpec[i].fileName, d-&gt;d_name);
              char *mainPath = path;
              strcat(mainPath, d-&gt;d_name);
  
              fileSpec[i].fileSize = stat_filesize(mainPath);
  
              printf(&quot;\t%s ---&gt; %ld\n&quot;, fileSpec[i].fileName, fileSpec[i].fileSize);
              i++;
              strcpy(mainPath, &quot;&quot;);
          }
      }
      closedir(directory);
  }
  </code></pre>
  <p>There's something I don't understand. Why is it that when I use <code>strcpy(mainPath, &quot;&quot;);</code> only the variable &quot;mainPath&quot; is not cleaned?</p>
  <p>This is because I need to pass the path as an argument.</p>