LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2004, 03:01 AM   #1
alix123
Member
 
Registered: Nov 2004
Posts: 63

Rep: Reputation: 15
Angry how to copy elemnts of two different structrue elements


iam not able to copy elemnts of one structure into another different structure

Iam givivng an example to explain what i Want ???????..

I have a structure for Example:-
/**********this is main file called main.c************/

#include"heade2.h"/*********see description below for the header2.h*********/

typedef enum(init,initkt)actiontype;
struct str1
{
int no
char * str;
actiontype action;
};

main()
{
my_client my_objects; /******see header2.h below*********/
str1 * obj ;
copy_structure(&myobjects,obj);
/**********here is the question how the copy strcutre will copy every element **/
/*******how will i allocate the memory to every elemt os structure using malloc*/


/***there ars some fucntion which uses str1****/
}



/**********main.c ends here ********************?



/*now again there is another structure in a header file header.h*/
struct str2
{
int no ;
char *str;

}

/*********** header.h ends here************/




/********now again i have another header file called header2.h*****/

typdef struct str2 my;

my my_client;

/**********header2.h ends here and i include this in main **********/


/******** i cannot shift the position of structure str1 becuause ther are amny dependencis it has in the main and the source code has been build like that so i have to follow the same organiztion of the source code *********/
 
Old 11-24-2004, 10:12 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
try memcpy
Code:
struct st1 *p;
struct st2 *q;
memcpy(p->no,q->no,sizeof(int));
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing forms elements with javascript djgerbavore Programming 2 06-03-2005 02:32 PM
odd behaviour of array elements in c++ markhod Programming 4 03-14-2005 09:58 AM
Why are some elements missing after using strcat() monil Programming 4 03-08-2005 07:40 AM
perl - get number of elements in an array AM1SHFURN1TURE Programming 3 03-07-2005 03:59 PM
The Elements Of Style: UNIX As Literature m0rl0ck General 7 10-03-2003 05:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration