Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with StrScan and StrRScan func

Status
Not open for further replies.

ShawnCoutts

Programmer
Jul 4, 2006
74
CA
i have a function that is attempting to compare 2 pointers to see if they point to the same place.

Code:
if(StrScan(Form1->Length->Text.c_str(), '.') != StrRScan(Form1->Length->Text.c_str(), '.')) {

in theory this code should work. Especially after checking to make sure that the pointers referenced the same thing.

Can someone explain why I cant compare 2 pointers like this?
 
Why do you think you can't do that? What results do you get?

(The Form1->Length->Text bit looks strange, but that should not be relevant here)
 
well i get the two pointers end up pointing to the same memory location and coming up not equal, so it enters the if block when its not supposed to.

Might I ask how you would do this?
 
What i am trying to do is make sure that the input into the field will parse properly into a double type. If there are too many decimal points in the number... say there are 2 decimal points for instance... the function flags it, and notifies the user that he/she needs to change that input. It works by looking for the first and last instances of the '.' and then compares the two pointers to see if they are equal. If the pointers are equal, then the function continues and skips the if block. Otherwise it sets a flag, and at the end of the function displays a message box notifying the user that they entered invalid input.
 
Your logic seems fine. I can't see any reason why it wouldn't work.
 
I found another solution. I coded a function that runs a pointer through the string and keeps count of the number of decimal points. if its greater than one, flag it.

Thanks for your help though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top