J
JR
I need some help. I am trying to return a dirent struct location so i
can access what the function found in main(). I dont understand
pointers very well and think that is were i am getting it wrong. If i
print everything from getdirlist everything is fine. I just cant pass
along the namelist scandir creates. Any help would be great.
JR
#include <dirent.h>
struct dirent getdirlist(char *dirstart)
{
struct dirent **namelist;
int n;
n = scandir(dirstart, &namelist, 0, alphasort);
if (n < 0) perror("scandir");
return **namelist;
}
int main()
{
struct dirent *dirlist;
int c=0;
char currentdir;
currentdir='.';
dirlist = getdirlist("/root");
while(c<sizeof(dirlist))
{
printf("%s\n",dirlist[c]->d_name);
c=c+1;
}
}
can access what the function found in main(). I dont understand
pointers very well and think that is were i am getting it wrong. If i
print everything from getdirlist everything is fine. I just cant pass
along the namelist scandir creates. Any help would be great.
JR
#include <dirent.h>
struct dirent getdirlist(char *dirstart)
{
struct dirent **namelist;
int n;
n = scandir(dirstart, &namelist, 0, alphasort);
if (n < 0) perror("scandir");
return **namelist;
}
int main()
{
struct dirent *dirlist;
int c=0;
char currentdir;
currentdir='.';
dirlist = getdirlist("/root");
while(c<sizeof(dirlist))
{
printf("%s\n",dirlist[c]->d_name);
c=c+1;
}
}