Solved

casting a pointer to structure variable

Posted on 1998-06-25
2
220 Views
Last Modified: 2010-04-02
If:

struct mystruct{
int num1
int num2
char something[10]
}my_s

int *mynum = NULL;

How do you cast "*mynum" to my_s.num1?
*mynum = &my_s.num1 (compile warnings)??
0
Comment
Question by:kulesk
2 Comments
 
LVL 1

Accepted Solution

by:
szetoa earned 50 total points
ID: 1251414
If I understand your question correctly, you want to assign
mynum to point to num1 inside the structure mynum.  Try this:

mynum = & my_s.num1;

Now you can assign value to mynum:

*mynum = 1; /* for example */

Hope this helps!!!
0
 

Author Comment

by:kulesk
ID: 1251415
Thanks!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now