![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
herby handcock Guest
|
search string within string |
Posted: Thu Jul 29, 2004 5:50 am |
|
|
I am trying to search a string for another string without any success.
I am using something like:
char mystring[] = "dsdsdswwrgd_ABC_13";
char asp[] = "_B64_";
fprintf(COM1, "%s\n", strstr(mystring, asp));
returns "_ABC_1" where did the "3" go? |
|
![](templates/subSilver/images/spacer.gif) |
herby handcock Guest
|
RE string within string |
Posted: Thu Jul 29, 2004 5:52 am |
|
|
Sorry, this should have been:
char mystring[] = "dsdsdswwrgd_ABC_13";
char asp[] = "_ABC_";
fprintf(COM1, "%s\n", strstr(mystring, asp));
returns "_ABC_1" where did the "3" go? |
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Jul 29, 2004 8:20 am |
|
|
Try the string function strstr().
ptr = strstr(s1, s2) - Search for s2 in s1. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Jul 29, 2004 9:05 am |
|
|
rnielsen wrote: | Try the string function strstr().
ptr = strstr(s1, s2) - Search for s2 in s1. |
That is what he is allready using.
The problem is not in 'finding' the string, but that the result appears to be truncated.
It is worth looking at 'string.h', since the function defintions are all there. Looking at this, the function walks forward through the first string, looking for the first character in the second string. Once this is found, it goes forward through both strings, and returns the address where the first character was found, when it reaches the end of the second string. As such, it should work.
Verify that the print works correctly with:
fprintf(COM1, "%s\n", mystring);
It may be something more insidious, like the compile dropping the last character of a constant string when loading it to RAM!.
Tell us the compler version (it may be a known problem).
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Jul 29, 2004 10:54 am |
|
|
DOH! I guess it would help to read through ALL of the text first, eh? *smacks forehead* |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Jul 29, 2004 10:59 am |
|
|
rnielsen wrote: | DOH! I guess it would help to read through ALL of the text first, eh? *smacks forehead* |
We have all done it (I usually refer to 'wall-head impact technology testing', when I have been really hard tracking something, and then the 'obvious' error is pointed out in five seconds by someone else... :-)
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|