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. Reading chunks of Data

Reading chunks of Data

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 Posts 5 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.
  • A Offline
    A Offline
    AbhiHcl
    wrote on last edited by
    #1

    Hi , I hv a char buffer(say 1024 bytes) with lots of data, I want to read data from that buffer, but at one time I can read only some of character(say 255 bytes). I need to read all the data from the buffer and place excatly after the last cahrcter I read (say after the first 255 bytes I need to put second part of the buffer and so on.. until the full buffer I read). Please help me in this regards.. If possible please provide me some sample code. Thanks..

    C E L 3 Replies Last reply
    0
    • A AbhiHcl

      Hi , I hv a char buffer(say 1024 bytes) with lots of data, I want to read data from that buffer, but at one time I can read only some of character(say 255 bytes). I need to read all the data from the buffer and place excatly after the last cahrcter I read (say after the first 255 bytes I need to put second part of the buffer and so on.. until the full buffer I read). Please help me in this regards.. If possible please provide me some sample code. Thanks..

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Looks like a fairly simple task to me. What's exactly your problem about? :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      1 Reply Last reply
      0
      • A AbhiHcl

        Hi , I hv a char buffer(say 1024 bytes) with lots of data, I want to read data from that buffer, but at one time I can read only some of character(say 255 bytes). I need to read all the data from the buffer and place excatly after the last cahrcter I read (say after the first 255 bytes I need to put second part of the buffer and so on.. until the full buffer I read). Please help me in this regards.. If possible please provide me some sample code. Thanks..

        E Offline
        E Offline
        elchupathingy
        wrote on last edited by
        #3

        for starting position to end of buffer_to_read_from
        for temporary variable i to length of secondary buffer
        copy a single from source(offset starting position) to destination buffer;
        increment variable i
        increase starting position by the length of the secondary buffer size

        That is probably what you are looking for. Simple thing really, should be able to figure it out quite simply with just a little bit of extra thought.

        A 1 Reply Last reply
        0
        • E elchupathingy

          for starting position to end of buffer_to_read_from
          for temporary variable i to length of secondary buffer
          copy a single from source(offset starting position) to destination buffer;
          increment variable i
          increase starting position by the length of the secondary buffer size

          That is probably what you are looking for. Simple thing really, should be able to figure it out quite simply with just a little bit of extra thought.

          A Offline
          A Offline
          AbhiHcl
          wrote on last edited by
          #4

          thanks for reply, My acutal dat is like char *str = "1,2,3\r\n1,3,4\r\n3,4,5\r\n1,3,5\r\n2,3,1\r\nCMD OK\r\n" but first time I m getting only char* temp = "1,2,3\r\n1,3,4\r\n3,4," I need to read upto last \r\n and keep the remaining (3,4) in some temporery variable, and the next time wen I'll get the another set of data then I need to append the tepory data with the new one, I hv to do the same task until I m not getting the "CMD OK\r\n". I need to do like that becz every comma seperated value has to be store in seperate array. Can u please send me some sample code for that.. Thanks..

          C 1 Reply Last reply
          0
          • A AbhiHcl

            thanks for reply, My acutal dat is like char *str = "1,2,3\r\n1,3,4\r\n3,4,5\r\n1,3,5\r\n2,3,1\r\nCMD OK\r\n" but first time I m getting only char* temp = "1,2,3\r\n1,3,4\r\n3,4," I need to read upto last \r\n and keep the remaining (3,4) in some temporery variable, and the next time wen I'll get the another set of data then I need to append the tepory data with the new one, I hv to do the same task until I m not getting the "CMD OK\r\n". I need to do like that becz every comma seperated value has to be store in seperate array. Can u please send me some sample code for that.. Thanks..

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

            this is how you may do it.

            //string array to store comma seperated data
            char buffer[100][10] = {0};
            int i = 0;

            char seps[] = "\r\n";
            bool ok = false;

            while(incoming data)
            {
            //hard-coded - newly read data
            char data[] = "1,2,3\r\n1,3,4\r\n3,4,";

            //copy to temp
            char temp\[100\];
            strcpy(temp, data);
            
                //tokenize
            char \*token = strtok( temp, seps );
            while( token != NULL )
            {
            	if(! strcmp(token, "CMD OK"))//end?
            	{
            		ok = true;
            		break;
            	}
            	strcat(buffer\[i++\], token);
            	token = strtok( NULL, seps );
            }
            
            if(ok);
                break;
            
            //last data complete?
            if( strcmp(&data\[strlen(data)-2\], "\\r\\n"))
                --i;
            

            }

            hope strtok is known to you. never ask here for this kinda simple codes ever. you may not get it more :|

            1 Reply Last reply
            0
            • A AbhiHcl

              Hi , I hv a char buffer(say 1024 bytes) with lots of data, I want to read data from that buffer, but at one time I can read only some of character(say 255 bytes). I need to read all the data from the buffer and place excatly after the last cahrcter I read (say after the first 255 bytes I need to put second part of the buffer and so on.. until the full buffer I read). Please help me in this regards.. If possible please provide me some sample code. Thanks..

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Dude, didn't some of us give the reply as well as the code to the exact same question you asked elsewhere? I too have given here. Why don't you try to work with them and not litter the forums with same questions.

              ...byte till it megahertz...

              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