0

I have following structure

typedef struct List_Node {
     struct File_Descriptor *data;
     char *key;
    struct List_Node *next;
}List_Node;

Now I inserted some values into the both the structures and want to access the data of type File_descriptor. How to do this?

I tried this

struct List_Node *ln1;
printf("%s", ln1.File_Descriptor->data);

but it is giving error

error: request for member ‘error: File_Descriptor’ in something not a structure or union` 
1
  • There is no structure inside the structure; only a pointer. (which could point to an incomplete type) Commented Oct 15, 2012 at 21:59

2 Answers 2

2

You just want:

struct List_Node *ln1;
printf("%s", ln1->data);

struct File_Descriptor is the type. data is the struct member name.

Also though the printf format looks entirely wrong. Not sure what you're trying to do there. %s is string, and data certainly doesn't look like a string.

Sign up to request clarification or add additional context in comments.

3 Comments

It can't be a good idea to use "%s" with an argument of type struct File_Descriptor*
@aschepler Indeed. Added that to my answer.
I made so many mistakes in my answer which you kindly corrected I just deleted it. +1.
1

I believe you are confusing the type name with the variable name. In order to access the data member of the List_Node struct, you use the following:

struct List_Node *ln1; // initialize this
printf("%s", ln1->data);

Don't forget that you first have to initialize the ln1 pointer to point to a valid memory location before dereferencing it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.