LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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: 705

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,696

Rep: Reputation: 232Reputation: 232Reputation: 232
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



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:38 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration