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