Thread: memcpy use?

  1. #16
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Can you show a loop that will copy each element?
    Element of the struct: no, can't be done.
    Element of the array: yes, already done in this thread.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  2. #17
    Registered User
    Join Date
    Dec 2004
    Posts
    77
    hammer please read my last reply I changed it since you read it and replied to it...

  3. #18
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>will this copy the data to elements 50 through 99 in big_car_buf.cardata[i] ?
    Well, assuming you overlook the fact that I made a small error (i should be declared outside the first for loop, otherwise I think it goes out of scope before this), yes it does - i leaves off at 50, and the second loop continues from there to 99.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #19
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Code:
    for(; i < 100; ++i)
       big_car_buf.cardata[i] = car_buf2.cardata[i - 50];
    In this bit of code, i is not re-initialised, therefore it will hold the value 50 as it did when it left the previous for loop. So, this loop will copy from elements 0 to 49, to elements 0 to 50 to 99.

    I would also recommend a minor change to the supplied code. I would declare i outside of the first for loop, not within it. This would ensure that it stays in scope for use in the next for loop.

    [beat! - maybe I should duck out of this one ]
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #20
    Registered User
    Join Date
    Dec 2004
    Posts
    77
    hammer thanks...sorry for being so hung up on memcpy and more importantly for being a bonehead!

  6. #21
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>hammer thanks
    thank hunter2, I was only butting in !
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #22
    Registered User
    Join Date
    Dec 2004
    Posts
    77
    sorry about that...it's late! thanks hunter!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Disagreement about memcpy
    By ch4 in forum C Programming
    Replies: 9
    Last Post: 05-28-2009, 10:12 AM
  2. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  3. Memcpy(); Errors...
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2006, 11:35 AM
  4. memcpy with 128 bit registers
    By grady in forum Linux Programming
    Replies: 2
    Last Post: 01-19-2004, 06:25 AM
  5. memcpy
    By doubleanti in forum C++ Programming
    Replies: 10
    Last Post: 02-28-2002, 04:44 PM