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. appending chunks of Bytes

appending chunks of Bytes

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structuresquestion
5 Posts 2 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.
  • C Offline
    C Offline
    chaitanya22
    wrote on last edited by
    #1

    Hello, am still having a problem with this appending. Am recieving data from a machine two times(i,e total lenght of recieving bytes:212) but am recieving them as length:x1 and length:x2)spliting into two chunks. count:1 //first chunk of data length:112//length si varying, not constant, say x1 0x65 0x66 0x67...... count:2// second chunk of data length:100//length si varying, not constant, say x2 0x23 0x40 0x46 0xcf.... How could i append the length of x2 bytes to x1, so that i should have total 212 bytes. i would be gald if anyone halps me out from this. BYTE buffer[1024]; BYTE array[1024];//the output data am recieving from machine is in buffer for(i=0;i<=lLength;i++) printf("#%x", buffer[i]); if(count>1) array[i]=buffer[i];//am assigning all the buffer values to array if count is greater than 1. "or" i can use memcpy() also, but there si no result; is it correct?? but i couldnt get append the whole data? could anyone plz help me for appending -- modified at 12:10 Thursday 9th March, 2006

    D 1 Reply Last reply
    0
    • C chaitanya22

      Hello, am still having a problem with this appending. Am recieving data from a machine two times(i,e total lenght of recieving bytes:212) but am recieving them as length:x1 and length:x2)spliting into two chunks. count:1 //first chunk of data length:112//length si varying, not constant, say x1 0x65 0x66 0x67...... count:2// second chunk of data length:100//length si varying, not constant, say x2 0x23 0x40 0x46 0xcf.... How could i append the length of x2 bytes to x1, so that i should have total 212 bytes. i would be gald if anyone halps me out from this. BYTE buffer[1024]; BYTE array[1024];//the output data am recieving from machine is in buffer for(i=0;i<=lLength;i++) printf("#%x", buffer[i]); if(count>1) array[i]=buffer[i];//am assigning all the buffer values to array if count is greater than 1. "or" i can use memcpy() also, but there si no result; is it correct?? but i couldnt get append the whole data? could anyone plz help me for appending -- modified at 12:10 Thursday 9th March, 2006

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      chaitanya22 wrote:

      How could i append the length of x2 bytes to x1, so that i should have total 212 bytes.

      Use memcpy().


      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

      "There is no death, only a change of worlds." - Native American Proverb

      C 1 Reply Last reply
      0
      • D David Crow

        chaitanya22 wrote:

        How could i append the length of x2 bytes to x1, so that i should have total 212 bytes.

        Use memcpy().


        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

        "There is no death, only a change of worlds." - Native American Proverb

        C Offline
        C Offline
        chaitanya22
        wrote on last edited by
        #3

        if(count>0) memcpy(array,buffer, 213); for(int i=0;i<=length;i++) printf("%x", array[i]); if i do so, again its copying with chunks in between the data. as i should copy the buffer of count:2 to buffer of count:1, so am using array[i+lLength]=lData[i]; //from starting of next chunk for(int i=0;i<=length;i++) {printf("%x", array[i]);} is this correct???

        D 1 Reply Last reply
        0
        • C chaitanya22

          if(count>0) memcpy(array,buffer, 213); for(int i=0;i<=length;i++) printf("%x", array[i]); if i do so, again its copying with chunks in between the data. as i should copy the buffer of count:2 to buffer of count:1, so am using array[i+lLength]=lData[i]; //from starting of next chunk for(int i=0;i<=length;i++) {printf("%x", array[i]);} is this correct???

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Consider:

          char arr1[12] = "Hello ";
          char arr2[6] = "World";
          memcpy(&arr1[6], arr2, 5 * sizeof(char));
          // arr1 now contains "Hello World"


          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

          "There is no death, only a change of worlds." - Native American Proverb

          C 1 Reply Last reply
          0
          • D David Crow

            Consider:

            char arr1[12] = "Hello ";
            char arr2[6] = "World";
            memcpy(&arr1[6], arr2, 5 * sizeof(char));
            // arr1 now contains "Hello World"


            "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

            "There is no death, only a change of worlds." - Native American Proverb

            C Offline
            C Offline
            chaitanya22
            wrote on last edited by
            #5

            Yes, Tahnk you for your answer. I got the solution.

            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