"Ben" <cr*********@yahoo.com> wrote in message
news:d9**************************@posting.google.c om...
(I am using gcc 3.2 on RH 8)
int name (struct str *name)
I call the above function like this:
struct str buf;
int conf = name(&buf);
int j;
for (j=0; buf.address[j]; j++) {
printf("%c", buf.address[j]);
}
If I do buf->address[j] instead of buf.address[j], it gives me error..
It should.
Why's that? aren't they the same thing?
Not at all. Why would you think so?
'.' is used to select a member from a struct
object 'directly' , using the struct object's name.
'->' is used to select a member from a struct object
'indirectly', using a pointer to that struct object.
struct s
{
int member;
};
struct s obj; /* struct */
struct s *p = &obj; /* pointer to struct */
obj.member; /* (1) direct access */
p->member; /* (2) indirect access, via a pointer */
(*p).member; /* (3) same as (2) */
(2) is simply 'shorthand' notation for (3).
Inside your function 'name()', you can access the struct
members with '->' (since the parameter is a pointer to
a struct). e.g. name->address. Alternatively,
(*name).address
BTW your function and its parameter have the same identifier.
Don't Do That. :-)
-Mike