Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. simple memcpy() question

simple memcpy() question

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnstonsk
    wrote on last edited by
    #1

    I have a number a different arrays.

    double t1[10];
    char t2[10];
    ...

    double cpT1[10];
    char cpT2[10];

    If I make a array of the same size to copy into can I use the memcpy() function like this?

    memcpy(cpT1, t1, sizeof(t1)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.

    memcpy(cpT2, t2, sizeof(t2));

    Or should I create a function that I pass the amount to the memcpy() function? If So how can I make it so that I can pass any array to the function? Thanks, steven

    C J 2 Replies Last reply
    0
    • J johnstonsk

      I have a number a different arrays.

      double t1[10];
      char t2[10];
      ...

      double cpT1[10];
      char cpT2[10];

      If I make a array of the same size to copy into can I use the memcpy() function like this?

      memcpy(cpT1, t1, sizeof(t1)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.

      memcpy(cpT2, t2, sizeof(t2));

      Or should I create a function that I pass the amount to the memcpy() function? If So how can I make it so that I can pass any array to the function? Thanks, steven

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      If the array are statically created (like in your example), that will work, otherwise not !

      J 1 Reply Last reply
      0
      • J johnstonsk

        I have a number a different arrays.

        double t1[10];
        char t2[10];
        ...

        double cpT1[10];
        char cpT2[10];

        If I make a array of the same size to copy into can I use the memcpy() function like this?

        memcpy(cpT1, t1, sizeof(t1)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.

        memcpy(cpT2, t2, sizeof(t2));

        Or should I create a function that I pass the amount to the memcpy() function? If So how can I make it so that I can pass any array to the function? Thanks, steven

        J Offline
        J Offline
        John M Drescher
        wrote on last edited by
        #3

        memcpy(cpT1, t1, sizeof(t1)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.
        memcpy(cpT2, t2, sizeof(t2));

        This will work fine. John

        J 1 Reply Last reply
        0
        • C Cedric Moonen

          If the array are statically created (like in your example), that will work, otherwise not !

          J Offline
          J Offline
          johnstonsk
          wrote on last edited by
          #4

          thanks, sj

          1 Reply Last reply
          0
          • J John M Drescher

            memcpy(cpT1, t1, sizeof(t1)); //Im thinking that the sizeof(t1) will return the size of the array t1 with all the data in it.
            memcpy(cpT2, t2, sizeof(t2));

            This will work fine. John

            J Offline
            J Offline
            johnstonsk
            wrote on last edited by
            #5

            thanks, sj

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups