yezi wrote:
Hi:
How to code for operation between 2 structures?
The structure's defination is :
struct sockaddr_in my_addr;
I need call a subfunction and pass the value in my_addr to the
subfuncition , which same structure but different name?
Thanks for any comments.
bin
........I'm not sure if I got your question correctly. I'm assuming you
want to know how to pass a structure (or it's members) to a function.
Here's an example:
struct foo {
int a;
int b;
};
struct foo foo1;
/*Passing entire structure*/
Function call: bar(&foo1);
Function defintion:
//if you want, you can use any other parameter name other than foo1
int bar(struct foo *foo1)
{
printf("%d, %d", foo1->a, foo1->b); //foo1 is a pointer so we use ->
return 0;
}
/*Passing a structure member*/
Function call: bar(&(foo1.a))
Function definition:
int bar(int *a)
{
printf("%d", a);
return 0;
}
HTH,
Hemanth