Cpmpare SMS sender no. with no. stored in .txt file

Login to reply to this topic.
Wed, 2007-09-19 10:40
Joined: 2007-07-24
Forum posts: 24

Hello friends,

I'm developing SMS inteceptor.

I want to intercept only those sms which comming from pertucular no. (Eg. 123456)

I'm able to intercept sms & read its text body.
I also can get sender no.

I'm comparing it with no. stored in .txt file, for that i used IF loop but still it not comparing
two nos.

Here is code....

......
........
..........
TPtrC from = header.FromAddress();
const TDesC& Sender_no= from;

TBuf16<200> Stored_No; // it contains stored no. (from .txt file)

if(!Sender_no.CompareC(Stored_No));        //compare nos..
{
.....
......
........
}

Please let me know what wrong in that IF LOOP condition?
It's not giving me any error.
But if both nos are differenr, still code in IF LOOP gets executed.... Puzzled


Wed, 2007-09-19 12:26
Joined: 2006-10-05
Forum posts: 80
Re: Cpmpare SMS sender no. with no. stored in .txt file

Hi,

SDK Help says:

CompareC()
TInt CompareC(const TDesC16& aDes) const;
Description
Compares data using the standard collation method.

Compares this descriptor's data with the specified descriptor's data using the standard collation method appropriate to the current locale.

Return value
TInt Positive, if this descriptor is greater than the specified descriptor. Negative, if this descriptor is less than the specified descriptor. Zero, if the content of both descriptors match.

So if both numbers are different, the return value will be anything but 0. So if you want to verify if both numbers are same,then you should write:
if( Sender_no.CompareC(Stored_No) == 0 ) //compare nos..
{
.....
......
........
}

Note: Why is there a semi-colon in your code after the If statement??

Moreover, you can simply do with Compare(). Why use CompareC() ?

Wed, 2007-09-19 12:35
Joined: 2005-11-20
Forum posts: 1242
Re: Cpmpare SMS sender no. with no. stored in .txt file

Well, yes, but what is the *deeper* reason it does not work, i.e. the if block gets executed with 0 *and* the if gets also executed with values other than 0 (something that is probably surprising and confusing)?

It is because in the way the condition is written the "!" operator will work with all the bits of the value, so e.g. !3 does not give 0 but -4, right?


René Brunner

  • Login to reply to this topic.