Using a structure containing a pointer

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I know this is a super basic question but I've googled and searched here to no avail.

I have a structure for example:

struct name {
char var1;
char var2;
char *var3;
} struct1

I want to use the pointer *var3 something like this:

struct1.*var3++ = x;

In other words I want to store the value 'x' at the address pointed to by struct1.var3 and then point to the next address.

My above syntax is incorrect. Can anyone help?

I'm not actually using GCC. I'm using CodeVision but since there is no CV forum on here I thought I'd ask here and see if I can translate to CV speak.

Shannon

Go electric!
Happy electric car owner / builder

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It should be

*(struct1.var3)++ = x;

I have to think about whether the parens are necessary, I was up way too late last night and my mind isn't back to full working order yet!

P.S. This is basic C so it works in any C compiler.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
typedef struct  {
  char var1;
  char var2;
  char *var3;
} name_s;

*struct1.var3++ = x;
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I'm using CodeVision but since there is no CV forum on here I thought I'd ask here and see if I can translate to CV speak.

Why not try on the "official" CodeVision list:
http://groups.yahoo.com/group/co...

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

...because I didn't know about it! Thanks Lee

And thank you others. Think I've got it now.

Go electric!
Happy electric car owner / builder