Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!decwrl!deccrl!bloom-beacon!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.programmer Subject: Re: Need a little example of scandir() Message-ID: <1991May22.154257.11469@athena.mit.edu> Date: 22 May 91 15:42:57 GMT References: <822@rocksanne.WRC.XEROX.COM> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 27 In article <822@rocksanne.WRC.XEROX.COM>, stein@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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710