Thread: memcpy usage

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    91

    memcpy usage

    Is there a way to :

    memcpy(m, k, sizeof(m))

    where m[6] and k is much larger but you want to copy just a subset?

    ie
    something like
    memcpy(m, k[3], sizeof(m)) where it starts at element k[3]

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well
    memcpy(m, k, sizeof(m))
    is
    memcpy(m, &k[0], sizeof(m))


    So
    memcpy(m, &k[3], sizeof(m))
    is entirely reasonable.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2020
    Posts
    91
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memcpy
    By ueg1990 in forum C Programming
    Replies: 3
    Last Post: 07-05-2012, 04:39 AM
  2. Help memcpy!
    By Kozay Novel in forum C Programming
    Replies: 9
    Last Post: 07-04-2012, 08:46 PM
  3. memcpy
    By mbooka in forum C Programming
    Replies: 10
    Last Post: 02-28-2006, 02:25 AM
  4. Help: About memcpy()
    By naruto in forum C Programming
    Replies: 41
    Last Post: 06-25-2004, 03:47 PM
  5. memcpy
    By doubleanti in forum C++ Programming
    Replies: 10
    Last Post: 02-28-2002, 04:44 PM

Tags for this Thread