View previous topic :: View next topic |
Author |
Message |
ferrarilib
Joined: 11 Jun 2005 Posts: 38
|
strstr |
Posted: Sat Jan 06, 2007 7:41 am |
|
|
hallo i have a answer abaut strstr()
i need find this char 0x21,0xFF
i do this ;
....
char ck[]={0x21,0xFF}
char InMSG[40];
if(strstr(InMSG,ck) != NULL)
{
}
this find nothing!
why ?
i thinw that problem is 0xFF
thanks . |
|
|
Ttelmah Guest
|
|
Posted: Sat Jan 06, 2007 8:04 am |
|
|
The problem is not 0xFF, but zero!....
Your search term, is not a string. A 'string' in C, must be terminated with the '\0' character. By declaring ck the way you do (with two character constants), it does not have the required terminator, and so the search will actually be looking for extra garbage characters after your 21 FF values (which will depend on what else is in memory immediately after the ck declaration), so the search will not work.
Declare ck as:
char ck[]={0x21,0xFF,'\0'};
and the search should start working.
Best Wishes |
|
|
ferrarilib
Joined: 11 Jun 2005 Posts: 38
|
|
Posted: Sat Jan 06, 2007 9:16 am |
|
|
thanks . |
|
|
|