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 6 5559
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
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
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
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
yezi <ye*****@hotmai l.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)cybers pace.org | don't, I need to know. Flames welcome.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 could create a class for
each structure, but I'm not sure how to get the data back and forth.
The example the "Extending and Embedding the Python Interpreter" manual
has examples of passing strings and ints using
PyArg_ParseTupleAndKeywords(), but...
|
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 what I really should do. I've had a
look through Programming Python and the Python Cookbook, which have given me
ideas, but nothing has gelled yet, so I thought I'd put the question to the
community. But first, let me be a little more detailed...
|
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 PowerC, a
16-bit DOS compiler); if there are nonstandard or "accidentally-works"
aspects, please let me know.
{This is the sort of situation where if I knew *what* to Google for, I
wouldn't *need* to... <grin>}
|
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 also a minor change in
class Mypropertyinfo, which I have commented out.
When using a structure, however, the second call to GetValue returns
"Default caption". Can anyone tell me why, and how I can make this work?
<code>
Imports System
|
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
End Structure
| |
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
groups for years, I figure it's time for me to contribute a little bit
back, maybe some people out there will find this useful.
* Introduction
This is a "how-to" style article, showing by example how to dynamically
|
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 that I use to communicate
to some unmanaged code in a DLL written in C. It is not complicated, but will
change and I would like to be able to sequentially access it without
explicitly referring to each and every element. Here is the structure:
|
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
set of examples, after decoding the HTML FORM contents, merely
verifies the text within a field to make sure it is a valid
representation of an integer, without any junk thrown in, i.e. it
must satisfy the regular expression: ^ *?+ *$
If the...
|
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 process - so the
data needs to be read in 1 record at a time then run thru the transformation
that may create new data value then everything is imported into a db to store.
I have multiple questions
1)we used to have an internal data structure...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |