View previous topic :: View next topic |
Author |
Message |
Freddie
Joined: 06 Sep 2003 Posts: 49
|
Reading Strings and comparing certain bytes |
Posted: Wed Dec 01, 2004 10:39 am |
|
|
I need to compare only certain parts of a string that is coming in over the PIC serial port. Using a PIC16F877.
In the code below "Copare OK" would never be printed. Is there a way to only compare the first 5 characters (ie, the "hello" portion) so the "Copare OK" would be printed?
Code: |
strcpy,(originalString,"hellothere");
strcpy(mycompareString,"hello");
if(stricmp(inString,mycommandString)==0)
{
printf("Compare OK");
}
|
|
|
|
Ttelmah Guest
|
|
Posted: Wed Dec 01, 2004 10:52 am |
|
|
Look at strncmp.
The stricmp function you use, ignores 'case' differences, while the strncmp function requires an exact match (so you may need to consider this). These functions are not exactly 'rocket science', and the code for them is in string.h, so if you require the case to be ignored, you could just 'hybridise' the two lots of code.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|