Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a data like this

C++
 char bufget[]="RE000022701500Ì200 0.00 6.113.937";

char preSendBuf[138];
int ptr=0;

int q=strlen(bufget);
for(int i=0;i<q;i++)
{
    while(*digits)
    {
    if((bufget[i]==*digits++))
    {
        preSendBuf[ptr]=bufget[i];
        ptr++;
//i know here we should decrement *digits index again to zero but how

    }
    }


}
preSendBuf[ptr]='\0';
ptr=0;
return 0;

actually data that i should get in
preSendBuf should be "RE000022701500200 0.00 6.113.937"
Posted
Comments
Red Chocolate 9-Nov-12 4:27am    
What is digits here?

It appears that someone has deleted my comments from yesterday on this issue. I have suggested to you a number of times how to process these data records, by using the information provided by the manufacturer. Each record has a predefined structure allowing you to access individual fields and validate them against the data specification. Make use of that information rather than continually trying to invent complicated parsing rules and making your programs more difficult that they need to be.
 
Share this answer
 
You have omitted that information, but digits (initially) appears to be a 0-terminated array of "acceptable" characters.

You are abusing the symbol digits for iterating over that set of characters, thereby losing the reference to the start of this array. What you should do instead is introduce a helper variable for that particular purpose (i. e. iterating), e. g.:

C++
for (int i = 0; i < q; ++i) {
   char* pdigits = digits;
   while (*pdigits) {
      if (budget[i] == *pdigits++) {
         // ...
      }
   }
}
 
Share this answer
 
Comments
Richard MacCutchan 9-Nov-12 6:11am    
OP has a document which spells out the exact structure of these records (referred to in a far earlier question) but will not or cannot use it. Also seems to have only rudimentary knowledge of C/C++ and yet is trying to develop a system for collecting live information from patient sensor devices in a hospital.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900