473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to code for pass one structure value to another structures?

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

Nov 15 '05 #1
6 5537
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

Nov 15 '05 #2
Singamsetty wrote:
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;


........I should have chosen a different variable name ( '1' looks like
a 'L') in my posting;-) No offense meant.

- Hemanth

Nov 15 '05 #3
Many thanks, that is what I want. the structure is too weird.
Singamsetty wrote:
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


Nov 15 '05 #4
you can pass struct to a function but the function proto type should be
like as foolows

return-type function-name(struct tag-name struct-name,other arg..(if
any));
if any mistake please report me

Nov 15 '05 #5
yezi <ye*****@hotmail.com> wrote:

[original post was about passing a structure to a function]
Many thanks, that is what I want. the structure is too weird.


Furthermore, passing a structure by value (rather than a pointer to
the structure) usually is more costly in terms of runtime resources.
It's usually best to pass the pointer.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #6
venkatesh wrote:
you can pass struct to a function but the function proto type should
be like as foolows


That's nice.

Brian

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: timothy.williams | last post by:
Hi. I trying to write an extension module to call some C libraries so I can use them in Python. Several of the library functions pass pointers to structures as arguments. I was thinking that I...
8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
39
by: gtippery | last post by:
Newbie-ish questions - I've been away from C for a _long_ time. It seems to me that there ought to be easier (or at least shorter) ways to do what this does. It does compile & run for me (with...
15
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is...
3
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String...
3
by: josh.kuo | last post by:
Sorry about the subject, I can't think of a better one. I recently wrote some PHP classes that I think might be of interest to this group. Since I have been reaping the benefits of reading news...
9
by: Bill Grigg | last post by:
All, Can anyone supply an example or reference to an example of using reflection to determine the data types and array lengths contained in a nested stucture in C#? Actually, it is a structure...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
2
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Have a complex process where I need to Import a large amount of data then run some transformations on this data then import into DataBase. The transformation involves multiple fields and multiple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.