Sponsored Content
Top Forums Programming linked list node with pointer to struct Post 302425544 by DreamWarrior on Friday 28th of May 2010 11:19:03 AM
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:
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

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

8. 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

9. 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

10. 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
bsearch(3C)															       bsearch(3C)

NAME
bsearch() - binary search a sorted table SYNOPSIS
DESCRIPTION
is a binary search routine generalized from Knuth (6.2.1) Algorithm B. It returns a pointer into a table indicating where a datum may be found. The table must be previously sorted in increasing order according to a provided comparison function. key points to a datum instance to be sought in the table. base points to the element at the base of the table. nel is the number of elements in the table. size is the size of each element in the table. compar is the name of the comparison function, which is called with two arguments that point to the elements being compared. The function must return an integer less than, equal to, or greater than zero indicating that the first argument (the key) is to be considered less than, equal to, or greater than the second argument (the array element). NOTES
The pointers to the key and the element at the base of the table should be of type pointer-to-element, and cast to type pointer-to-void. The comparison function need not compare every byte, so arbitrary data can be contained in the elements in addition to the values being compared. Although declared as type pointer-to-void, the value returned should be cast into type pointer-to-element. RETURN VALUE
A NULL pointer is returned if the key cannot be found in the table. EXAMPLES
The example below searches a table containing pointers to nodes consisting of a string and its length. The table is ordered alphabetically on the string in the node pointed to by each entry. This code fragment reads in strings and either finds the corresponding node and prints out the string and its length, or prints an error message. #include <stdio.h> #include <stdlib.h> #include <string.h> #define TABSIZE 1000 struct node { /* these are stored in the table */ char *string; int length; }; struct node table[TABSIZE]; /* table to be searched */ . . . { struct node *node_ptr, node; /* routine to compare 2 nodes */ int node_compare(const void *, const void *); char str_space[20]; /* space to read string into */ . . . node.string = str_space; while (scanf("%s", node.string) != EOF) { node_ptr = (struct node *)bsearch((void *)(&node), (void *)table, TABSIZE, sizeof(struct node), node_compare); if (node_ptr != NULL) { (void)printf("string = %20s, length = %d ", node_ptr->string, node_ptr->length); } else { (void)printf("not found: %s ", node.string); } } } /* This routine compares two nodes based on an alphabetical ordering of the string field. */ int node_compare(const void *node1, const void *node2) struct node *node1, *node2; { return strcoll(((const struct node *)node1)->string, ((const struct node *)node2)->string); } WARNINGS
If the table being searched contains two or more entries that match the selection criteria, a random entry is returned by as determined by the search algorithm. SEE ALSO
hsearch(3C), lsearch(3C), qsort(3C), tsearch(3C), thread_safety(5). STANDARDS CONFORMANCE
bsearch(3C)
All times are GMT -4. The time now is 11:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy