title: Listing all files in current directory to a String in C
body: <p>Ok so I'm trying to list all the files of the current directory directory to a String in C.
  The files in the current directory are: </p>
  
  <p>myftpclient.c , myftpclient.o, myftpserver.c, myftpserver.o</p>
  
  <pre><code>char * list(void) 
  {
      DIR *dp; // directory var
      struct dirent *ep;
      char str[256] ;
      int n = 0 ;
      dp = opendir ("./");
      if (dp != NULL)
      {
          while ((ep = readdir (dp)))
          {
              int curLen = strlen((ep-&gt;d_name)) ;
              strncat(str, (ep-&gt;d_name), curLen) ;
              strncat(str, "\n", 1) ;
              n += curLen + 1 ;
          }
          str[n] = '\0' ;
          (void) closedir (dp);
      }
      else
          perror ("Couldn't open the directory");
  
      return str ;
  }
  </code></pre>
  
  <p>This is my call to it:</p>
  
  <pre><code>char * str = malloc(256) ;
  str = list() ;
  </code></pre>
  
  <p>My output when I print the string is:
  <code>B0</code></p>
  
  <p>Which is not even close to correct. What am I doing wrong? </p>