Please solve this(Structure Program)

Joined
May 20, 2010
Messages
4
Reaction score
0
this is my program..............
struct name
{
int a;
char b[10];
char c;
};
int main()
{
struct name *p;
char *n;
n = (char *)malloc(3 * sizeof(char));
n = (char *)p;
What i want to do is i want to access structure through character pointer n......like
" n->a=3; "
what the problem in above line is its not working.showing error.
" error: request for member ‘a’ in something not a structure or union"...........
i dont know why............iam having doubt whether we can assign
" n = (char *)p; "
this line ...............if its correct can any one finish this program......................
 
Joined
Jun 8, 2009
Messages
1
Reaction score
0
n->a is not possible with n as it is a char *.

struct name
{
int a;
char b[10];
char c;
};
int main()
{
struct name *p;
char *n;
n = (char *)malloc(3 * sizeof(char));
p = (char *)n;

then use as p->a
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top