LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-25-2006, 02:57 PM   #1
true_atlantis
Member
 
Registered: Oct 2003
Distribution: fedora cor 5 x86_64
Posts: 639

Rep: Reputation: 30
access struct member error


if i have this

Code:
void ll_print(llnode **head){
    while((*head).next!=NULL)
        printf("%s\n",(*head).item);
}
where

Code:
struct llitem{
    char item[200];
    struct llitem *next;
};

typedef struct llitem llnode;
why do i get this error?

llist.c:13: error: request for member ‘next’ in something not a structure or union
llist.c:14: error: request for member ‘item’ in something not a structure or union


and how do would i go about accessing next or item?
 
Old 04-25-2006, 03:03 PM   #2
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
*head is a pointer to a structure, so you gotta use the arrow, (*head)->next
 
Old 04-25-2006, 03:04 PM   #3
addy86
Member
 
Registered: Nov 2004
Location: Germany
Distribution: Debian Testing
Posts: 332

Rep: Reputation: 31
llnode **head
Are you sure that's what you meant (instead of llnode *head)?

By the way:
head->next
is short for
(*head).next
(and better readable).

Edit:
Code:
while((*head).next!=NULL)
        printf("%s\n",(*head).item);
will get you into an endless loop (if head->next != NULL ). You forget to move to the next node in the list.

Last edited by addy86; 04-25-2006 at 03:07 PM.
 
Old 04-25-2006, 03:43 PM   #4
true_atlantis
Member
 
Registered: Oct 2003
Distribution: fedora cor 5 x86_64
Posts: 639

Original Poster
Rep: Reputation: 30
my problem was i needed (**head) in those two lines. i know the -> notation is better, i just have always used (*bla).

bad habbit... thanks
 
Old 04-25-2006, 05:00 PM   #5
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Code:
    while((*head).next!=NULL)
        printf("%s\n",(*head).item);
should be
Code:
    while((*head)->next)
    {
        printf("%s\n",(*head)->item);
        head = (*head)->next;
    }
[edit] or (**head).next

I'm bad. Got to admit it I didn't read the other posts before this.

Last edited by dmail; 04-25-2006 at 05:08 PM.
 
  


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
Can't access methods of a struct kornerr Programming 2 01-02-2006 11:19 AM
struct member alignment wmoti Programming 2 10-10-2005 05:24 AM
g++ and wrong struct member addresses / struct size misreporting sonajiso Linux - General 5 05-22-2004 10:16 PM
switch statement converting struct char to struct int oceaneyes2 Programming 2 12-10-2003 04:30 PM
using struct type X as pointer in struct X. worldmagic Programming 1 10-28-2003 02:06 PM

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

All times are GMT -5. The time now is 03:12 AM.

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