title: writing ls from scratch recursively
body: <p>I am working on a simple project to implement "ls -R" from scratch.  Whenever I run what I have, my program just keeps searching the root directory over and over again.  What am I doing wrong?</p>
  
  <pre><code>void lsR(char dirName[]) {
  /*
  The recursive function call.  
  */
  
  DIR *dir;
  struct dirent *directory;
  struct stat fileStat;
  char type;
  char **nameList[MAX_RECURSIVE_FILES];
  struct passwd *user;
  int count = 0;
  int i = 0;
  
  
  printf("\n");
  printf("./%s :\n", dirName);
  printf("\n");
  
  
  if ((dir = opendir(dirName)) == NULL) {
      perror("opendir error:");
      return;
  }
  
  while ((directory = readdir(dir)) != NULL) {
  
  
      if (stat(directory-&gt;d_name, &amp;fileStat) &lt; 0) {
          perror("fstat error:");
          return;
      }
      if (fileStat.st_uid == 1) {
          continue;
      }
  
      user = getpwuid(fileStat.st_uid);
      printf("%s ", directory-&gt;d_name);
  
      fileType(&amp;fileStat, &amp;type);
      if ((type == 'd') &amp;&amp; (count &lt; MAX_RECURSIVE_FILES)) {
  
          nameList[count] = malloc(sizeof(char)*MAX_STRING_LENGTH);
          strncpy(nameList[count++], directory-&gt;d_name, MAX_STRING_LENGTH);
      }
  
  }
  closedir(dir);
  printf("\n");
  for (i=0; i&lt;count; i++) {
      printf("Calling lsR on: %s\n", nameList[i]);
      lsR(nameList[i]);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>When it executes, I get the following output:</p>
  
  <p>"./. : </p>
  
  <p>., .., ... all other files in my current working directory ....</p>
  
  <p>./. :</p>
  
  <p>., .., ... all other files in my current working directory...</p>
  
  <p>"</p>