I don't know why you are doing these many things to get the files in the directory and print the file names with its full path.
You can do this by opendir and readdir functions.I have developed this code in linux environment.
Code:
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include<unistd.h>
#include <dirent.h>
DIR *db;
struct dirent *dirp;
main()
{
char directory[50];
printf("Enter the directory name : ");
scanf("%s",directory);
if((db=opendir(directory))!=NULL)
{
while((dirp=readdir(db))!=NULL)
{
printf("file name : %s/%s \n",directory,dirp->d_name);
}
}
else
{
printf("Can not open directory\n");
}
}
Thanks