I run this program to output the contents of the current working directory. I get the wrong output. Program is listed below with the output I get posted after it.
code
#include <stdio.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int main ()
{
DIR *gdir = NULL;
gdir = opendir(".");
struct dirent *hdir = NULL;
//hdir.d_ino = 123;
//hdir->d_name[256] = NULL;
if (gdir == NULL)
{
printf ("Could not open directory.");
exit (3);
}
while ( hdir = readdir(gdir) )
{
if (hdir == NULL)
{
printf ("Could not read from directory.");
//printf ("%d\n", i);
exit (3);
//printf ("hdir.d_ino: %ld", hdir.d_ino);
}
else
{
printf ("Name: %25s\n", hdir->d_name);
}
//i++;
}
//printf ("%d\n", i);
closedir(gdir);
//printf ("hdir.d_reclen: %u", hdir.d_reclen);
system ("PAUSE");
return 0;
}
output
Name:
Name:
Name:
Name:
Name: ry.c
Notice the ry.c
file with the .c
file extension. That is one of the files in the current working directory. I do not understand why only one truncated file name is outputted where the other files are not.
platform details
I have the current mingw installation, compiling with gcc, on windows 8. I am using Windows command line to compile.