473,396 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

accessing pointer inside a nested structure

i had a structure as follows:
Expand|Select|Wrap|Line Numbers
  1. struct a{
  2.  int x;
  3.  struct b{
  4.   int y;
  5.   b *next;
  6.  }b;
  7. };
when i try to access as follows:
Expand|Select|Wrap|Line Numbers
  1. struct a *a;
  2. a->b=a->b->next;
i got the following error:
base operand of ‘->’ has non-pointer type
anyone please help me out.. TIA...
Mar 19 '14 #1
1 1350
weaknessforcats
9,208 Expert Mod 8TB
First, this won't work:

Expand|Select|Wrap|Line Numbers
  1. struct a *a;
You cannot have a struct and a variable with the same name. I changed this to:

Expand|Select|Wrap|Line Numbers
  1. struct a *var;
Now this won't work:

Expand|Select|Wrap|Line Numbers
  1. var->b=var->b->next;
for several reasons. var->b is meaningless since b is a struct. you need to say which member of b gets the assignment.

Also b->next won't work because b is not a pointer. That needs to be changed to b.next

If I choose the next member of b I get:

Expand|Select|Wrap|Line Numbers
  1. var->b.next=var->b.next;
which assigns a variable to itself. But it does compile.

What are you trying to do?
Mar 19 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jason | last post by:
How do you access an int pointer inside a struct. This is how it seems like it would work to me, but it doesn't... struct maze { int num; int * roomnum; }; void setmaze(struct maze * maze)...
15
by: junky_fellow | last post by:
I am trying to find the offset of a member "mbr" inside a structure "str" as follows: offset = &(struct str *)0->mbr; But, on compilation I get the following error: cc: Error: m1.c, line 55:...
2
by: prakashgkhaire | last post by:
i have two structure where first structure consists val and structure pointer(linklist), 2nd structure consists, val, a varialbe of first structure, pointer of structure. Now i found to pass the...
2
by: Opteron64 | last post by:
Hi, I'm trying to create and initialise a dynamic array within a nested structure. The structure is defined as followed: (C++ code) typedef unsigned char uchar; typedef unsigned int uint; ...
4
by: needhlp2 | last post by:
What is the advantage of using a pointer to a structure as a parameter to a funtion, instead of the structure itself? -the code is easier to read -it is more efficient because the structure is...
7
by: mohammadthalif | last post by:
Hello friends, struct datas{ int *a,*b; } *name; can you explain me how can i get the data at location pointed by *a and *b. i tried,
3
by: tomi | last post by:
Help please Ho can I write following (from C#) thing in VB.NET ? IntPtr pointer = new IntPtr(&mode) mode is a instance of some structure. I cannot find any solution. I need to pass the...
2
upadhyad
by: upadhyad | last post by:
I have defined a new structure: ================== struct IDnTime { char previousEdate; struct tm theTime; struct tm *ptr; time_t t; } IDnTimeArray;
0
by: sarabonn | last post by:
Hello everyone, Iam using cookcomputing xmlrpc in c#.Net. My server xmlrpc call function is like this api = (('object_id', 'ASCII string', 1), ('services',...
0
by: mark1bristol | last post by:
Let me preface this by I am very new to python programming... I was looking at an old discussion about this that basically showed how to create a pointer to a structure to send to a C function in a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.