LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 08-15-2006, 05:09 AM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 704

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


Hi,
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...

Thanks
 
Old 08-15-2006, 09:39 AM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,536

Rep: Reputation: 148Reputation: 148
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, 11:06 AM   #3
xhi
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 *..

(*namelist)[i]
 
  


Reply


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 01:47 PM
how can I iterate over csv values using Ruby Joseph Schiller Programming 1 02-20-2006 08:29 PM
Array structs - passed to function cdog Programming 4 02-02-2006 03:07 PM
confusing array of structs kpachopoulos Programming 1 11-23-2005 02:13 PM
Bash: Iterate through $@ (easy++) beatnik007 Programming 2 04-03-2004 01:39 AM


All times are GMT -5. The time now is 09:41 PM.

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