Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Copy String structure "A" to string structure "B"
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Walter Roberson, post: 2403833"] :I need copy from structure "A" to "B" that contains "strings" in a one line code. In the code you show, you are not copying structure to structure: you are copying from a character array to a structure. :typedef struct tHeader{ : char field1[4]; : char field2[3]; : char field3[2]; : char field4[1]; :}; :strcpy(buffer,"ABCDEFGHIJKLMNOPQRSTUVWXYZ"); :memcpy(pHeader,&buffer,sizeof (struct tHeader)); What about internal padding and alignments? :printf("field1 : %s : ",pHeader->field1); :pHeader->field1 ==>"ABCD" You don't null terminate your strings, so the output could run on indefinitely. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Copy String structure "A" to string structure "B"
Top