Solved

casting a pointer to structure variable

Posted on 1998-06-25
2
241 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

808 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