title: Placing strings returned from readdir() into a char **
body: <p>I would like to make an array of strings that hold all of my regular files in the current directory</p>
  
  <p>I have the following</p>
  
  <pre><code>DIR *d = opendir(".");
  struct dirent *dirent;
  struct stat fileStat;
  char **files;
  
  while (dirent = readdir(d)) {
      stat(dirent-&gt;d_name, &amp;fileStat);
  
      if (S_ISREG(fileStat.st_mode)) {
  
      }
  
  }
  
  closedir(d);
  </code></pre>
  
  <p>I tried mallocing on the go (in the while loop) each element because the # of regular files in my folder is not predetermined. However, I keep getting segfaults. any ideas?</p>