Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-15-2006, 06:09 AM   #1
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705

Rep: Reputation: 30
c: iterate an array of structs

i have a pointer to an array of (dirent) structs -struct dirent ***namelist. I want to read each struct after another. Can i do "*namelist[i]" for i=1,2,...? Or do i have to something like
"(**namelist)+sizeof(dirent)" to read the next entry of the array? Please explain and clear out what i have written, because there is a confusion in my head...

Old 08-15-2006, 10:39 AM   #2
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,578

Rep: Reputation: 191Reputation: 191
Both methods are correct (I'm not sure why you need ***, but that's another story). They have the same effect.
Old 08-15-2006, 12:06 PM   #3
Senior Member
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
the second one would work as is, the first would need an extra set of parens to correctly derefernce the ptr to the array, since [] has higher precedence than *..



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Iterate through regular expression results in Perl rose_bud4201 Programming 1 04-14-2006 02:47 PM
how can I iterate over csv values using Ruby Joseph Schiller Programming 1 02-20-2006 09:29 PM
Array structs - passed to function cdog Programming 4 02-02-2006 04:07 PM
confusing array of structs kpachopoulos Programming 1 11-23-2005 03:13 PM
Bash: Iterate through $@ (easy++) beatnik007 Programming 2 04-03-2004 02:39 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:49 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration