/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that reads the first five files in directory twice. */
#include <stdio.h>
#include <dirent.h>

int main() {
    DIR *dirp;
    struct dirent *direntp;
    int i;
    
    dirp = opendir( "." );
    for(i=0; i<5;i++) {
      direntp = readdir( dirp );
      printf( "%s\n", direntp->d_name );
    }
    rewinddir(dirp);   /* reset the position of the directory stream to which
                     dirp refers to the beginning of the directory. */
    /* read the first five files again */
    for(i=0; i<5;i++) {
      direntp = readdir( dirp );
      printf( "%s\n", direntp->d_name );
    }
    closedir( dirp );
}
