title: how can i make use of dirent.h file to print the files in a directory?
body: <p>I need to print .c files, executables, and directories in seperate color. Please suggest me some ideas. Thanks in advance</p>
  
  <pre><code>int main(void)
  {
  
          DIR *d;
          int iNum = 0;
          struct dirent *dir;
          char *ptr = ".";
          char *ptr1 = "..";
  
          d = opendir(".");
  
          if (d)
          {
  
                  while ((dir = readdir(d)) != NULL)
                  {
                          if(strcmp(ptr,dir-&gt;d_name) &amp;&amp; strcmp(ptr1,dir-&gt;d_name))
                          {
                                  printf("%d\n", dir-&gt;d_type);
                                  printf("%s\n", dir-&gt;d_name);
                                  iNum++;
                          }
                  }
                  closedir(d);
          }
          printf("the number of files are %d\n",iNum);
  
          return(0);
  }
  </code></pre>