Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Visual-Studio
i have a data like this
 
 
	 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 8-Nov-12 6:25am
Comments
Member 9562996 at 9-Nov-12 4:27am
   
What is digits here?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.:
 
for (int i = 0; i < q; ++i) {
   char* pdigits = digits;
   while (*pdigits) {
      if (budget[i] == *pdigits++) {
         // ...
      }
   }
}
  Permalink  
Comments
Richard MacCutchan at 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)

  Print Answers RSS
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 BillWoodruff 108
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100