title: save readdir into a buffer in C
body: <p>I'm using <code>readdir()</code> to read to output all the files in a directory. The problem is that I need to save the strings into a buffer. Is there any way to save the output into a buffer or file descriptor etc? </p>
  
  <p>Here is my code:</p>
  
  <pre><code>  DIR *directory;
    struct dirent *dir;
  
    directory = opendir();
  
    while ((dir = readdir(directory)) != NULL) {
      printf("%s\n", dir-&gt;d_name);
    }
  
    closedir(directory);
  </code></pre>