linked list node with pointer to struct


 
Thread Tools Search this Thread
Top Forums Programming linked list node with pointer to struct
# 1  
Old 05-28-2010
linked list node with pointer to struct

Suppose to have:

Code:
struct Tstudent
{
   string name, surname;

   int matriculation_num;
};

struct Tnode
{
   Tstudent* student;

   Tnodo* next;
} L;

I want to deference that "student" pointer. For example, I tried with:

Code:
*(L->student).matriculation_num

but it not worked, as terminal says:

Code:
listaStud.cc:228: error: request for member ‘matriculation_num' in ‘L->Tnodo::student', which is of non-class type ‘Tstudent*'

So how can I access to data contained in "student" from L ?
# 2  
Old 05-28-2010
you again!

L.student->name
This User Gave Thanks to bigearsbilly For This Post:
# 3  
Old 05-28-2010
Yeah, above... So you under stand. L is NOT a pointer, thus, the "." notation is how you "navigate" into that structure. The student member in L IS a pointer, thus, the "->" notation (which is equal to "(*x).") navigates that.

If you had:

Code:
struct test
{
  int data;
  
};

struct test2
{
  struct test *ptr;
  struct test  nonPtr;
  
};

void main()
{
  struct test2  test2Data;
  struct test2 *test2Ptr = &test2Data;

  test2Data.ptr = &test2Data.nonPtr;

  test2Data.nonPtr.data = 42;
  test2Data.ptr->data = 42;
  test2Ptr->nonPtr.data = 42;
  test2Ptr->ptr->data = 42;
}

You can see the pattern.

Last edited by DreamWarrior; 05-28-2010 at 12:42 PM..
This User Gave Thanks to DreamWarrior For This Post:
# 4  
Old 05-29-2010
Glad to see you too, bigearsbilly. Smilie

Thank you guys.
# 5  
Old 05-31-2010
glad to help Luke!
pointers are hard to grasp.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to delete the last node in a linked list.?

How to delete the last node in a single linked list given only the pointer to last node ? Head node will not be given. (5 Replies)
Discussion started by: VSSajjan
5 Replies

2. UNIX for Advanced & Expert Users

Get pointer for existing device class (struct class) in Linux kernel module

Hi all! I am trying to register a device in an existing device class, but I am having trouble getting the pointer to an existing class. I can create a class in a module, get the pointer to it and then use it to register the device with: *cl = class_create(THIS_MODULE, className);... (0 Replies)
Discussion started by: hdaniel@ualg.pt
0 Replies

3. Programming

Declare member of struct as a pointer in c

I have a uint8_t *C = malloc(24*sizeof(uint8_t)); I need to send some integers and this *C to another node(in ad hoc network). So I am going to use a struct ` struct fulMsg { int msgType; int msgCount; //uint8_t *CC; } fulMsg_t; typedef struct fulMsg fulMsg_tt;` there is a method... (1 Reply)
Discussion started by: chap
1 Replies

4. Programming

Check The value a pointer returned by struct s_client != 0

Hi guys , i got segment fault , and when i trace , found it happens since the value of pointer which is returned by Struct S_client (*ptr) is zero if (ptr !=0)i know , adding above line of code is not the solution and not correct for the case since above line only check for the pointer... (1 Reply)
Discussion started by: pooyair
1 Replies

5. Programming

unidirectional linked list pointer problem

I am trying to test some operations on a directed list. However, the declaration of a pointer is giving me trouble. I seem to have done something incorrectly because I get an error: "listtest.c:29: warning: 'p' may be used uninitialized in this function" Can anyone help? This is my code... (6 Replies)
Discussion started by: bluetxxth
6 Replies

6. Programming

how do edit a node in a singly linked list in C?

If i have a linked list in C, how do I edit a node in it? Without ruining the whole list, by this i mean end up making it null or circular... (since it has to be linear and has to stop somewhere):wall: Can some one provide an example, making it have like 5 nodes, and then edit a string of the... (3 Replies)
Discussion started by: omega666
3 Replies

7. Programming

how to check if something exists in a struct linked list?

can someone provide an example of a struct linked list, where it has strings as its values, and then how do I check if a specific string (say called buffer) exists in the list of structs? i dont understand how to make a copy of it to check with this is what i have ... (0 Replies)
Discussion started by: omega666
0 Replies

8. Programming

Dereferencing pointer to a shared memory struct

I have what should be a relatively simple program (fadec.c) that maps a struct from an included header file (fadec.h) to a shared memory region, but I’m struggling accessing members in the struct from the pointer returned by shmat. Ultimately, I want to access members in the shared memory structure... (2 Replies)
Discussion started by: arette
2 Replies

9. Programming

Linear linked list node delete

Given an in-between(any node not at the start and end of the linked list) node within a singly linear linked list, how to delete that node, when head pointer of list is not given? (13 Replies)
Discussion started by: rupeshkp728
13 Replies

10. Programming

Pointer to a struct (with pointers) *** glibc detected *** double free

I am using a structure defined as follows struct gene_square { double *x; double *y; };I have class, with a member function which is a pointer of this type: gene_square* m_Genes;I am allocating memory in the constructors like this: m_Genes = new gene_square; for (ii=0;... (1 Reply)
Discussion started by: jatoo
1 Replies
Login or Register to Ask a Question