Hi!
I have to make a program, wich lists all files in current dir, and then save all file names into an array.
My program doesn't work ! Can you tell me why?
Thanks a lot:)
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
int main(void)
{ FILE *fp;
DIR *d;
struct dirent *dir;
char *filenames[20];
int i=0;
int k,l;
d = opendir(".");
if (d)
{
while ((dir = readdir(d)) != NULL)
{
filenames[i]=(dir->d_name);
printf("%d",i);
printf(filenames[i]);
printf("\n");
i++;
}
closedir(d);
}
printf(filenames[3]);
// *filenames[i]='\0';
system ("pause");
return(0);