473,654 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copy a Structure

Hi ,
in C, How do I copy a contents of a Structure pointer to a Structure
Variable. e.g
struct A var1;
struct A *Var2;

I want to copy contents of Structure pointed to by Var2 to a Structure var1.
Is there any standard library function to do the same?

Thanks and Regards,
Nov 17 '05 #1
3 1233
Hi Pravin!
in C, How do I copy a contents of a Structure pointer to a Structure
Variable. e.g
struct A var1;
struct A *Var2;


var1 = *Var2;

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2
Thanks Jochen,
var1=*var2 will copy the contents of structure pointed
to by var2 into var1. One more thing I wanted to ask was how do I copy the
contents of the structure var1 into the structure pointed to by var2?
var2=&var1 will make var2 point to the var1 struture.

thanks again,

"Jochen Kalmbach [MVP]" wrote:
Hi Pravin!
in C, How do I copy a contents of a Structure pointer to a Structure
Variable. e.g
struct A var1;
struct A *Var2;


var1 = *Var2;

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Nov 17 '05 #3
Pravin Prabhu <Pr**********@d iscussions.micr osoft.com> wrote:
Thanks Jochen,
var1=*var2 will copy the contents of structure pointed
to by var2 into var1. One more thing I wanted to ask was how do I copy the
contents of the structure var1 into the structure pointed to by var2?
var2=&var1 will make var2 point to the var1 struture.
*Var2 = var1;
thanks again,
Schobi
[...]


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Coming back to where you started is not the same as never leaving"
Terry Pratchett
Nov 17 '05 #4

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

Similar topics

2
3458
by: Anna | last post by:
Hi all. I am trying to write a stylesheet that will structure the input HTML file in the following way: For each heading of level n it needs to enclose the heading and all its content until the next heading of the same level within the level tag. Example input file:
4
612
by: Stephan Tobies | last post by:
Hi everyone, I am looking for a good data structure that could be used to represent families of trees with shared sub-trees and copy-on-write semantics. On a very abstract level, I would like to have an API like this: Let Node be a suitably defined data structure. Then the following functions shall be supported:
15
38172
by: Sourcerer | last post by:
Hi all. Can I do this to duplicate the contents of struct a in struct b struct myStruct a, b, *aptr, *bptr; aptr = a; bptr = b; Do something to initialize contents of structure a memcpy(bptr, aptr, sizeof(myStruct));
1
2238
by: Brad | last post by:
Using vb.net, I am attempting to copy a byte array buffer to a structure but need to specify an offset, in bytes, from the top of the structure. I have studied the Marshal class but it appears I can only specify the structure name...
4
12442
by: Dennis | last post by:
I have several Data Structures, say "mystruct" which contain arrays of bytes, other structures, etc. I then dimension a variable (var1) as "mystruct" and set the various elements var1 to data. I then dimension another variable (var1save) as "mystruct" and set var1save = var1 with the intent of changing var1 data elements and subsequently reasigning var1 back to it's original values of var1save. VB.Net makes only a shallow copy of var1...
7
2733
by: Just Me | last post by:
I know (or at least think) the following is not correct. The comment says what I want to do, but I think the code will copy the data not the address. Is this one of the things that can't be done with VB? Any suggestions? Thanks
4
5162
by: Férnas | last post by:
Hey guys, In my app, I have a DataTable named "dta"... If i create a new variable of DataTable type named "dta2", and assign the dta as value, it creates a reference to dta, then, when I make changes in dta, dta2 is also changed... For example:
19
5720
by: ivan.leben | last post by:
Let's say I have a piece of allocated memory which I want to expand and reuse if possible or allocate in a different part of RAM if resizing is not possible, however, in the latter case I don't care about the old data and I don't need to copy it to the new location. Is there a standard function that could do that? As far as I understand the description of the realloc() function, it _always_ copies the data to the new location, even if that...
7
2149
by: pereges | last post by:
which one do you think is better ? I need to make my program efficient and in some places I have passed the copy of a variable which makes life some what easy while writing huge expressions but they do requrie much more memory than a simple pointer.
0
8379
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8294
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
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...
0
8709
jinu1996
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...
1
6162
isladogs
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...
0
5627
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();...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2719
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
1
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.