Need a little example of scandir()

Jonathan I. Kamens jik at athena.mit.edu
Thu May 23 01:42:57 AEST 1991


In article <822 at rocksanne.WRC.XEROX.COM>, stein at WRC.XEROX.COM (Adam Stein) writes:
|> I have been trying to use scandir() with little success.
|> ...
|> 
|> -----Example----------Example----------Example----------Example---------
|> ...
|> 	struct direct *namelist;

  Here's the problem.  Scandir does not create an array of struct direct, it
creates an array of struct direct *.  Therefore, this declaration should read

	struct direct **namelist;

|> ...
|> 	  printf("Name -> <%s>\n",namelist[loop].d_name);

  Since namelist is now an array of pointers instead of an array of
structures, you need to use -> indirection to get at its contents.  This line
should read

	  printf("Name -> <%s>\n",namelist[loop]->d_name);

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.unix.programmer mailing list