CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

search string within string

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
herby handcock
Guest







search string within string
PostPosted: Thu Jul 29, 2004 5:50 am     Reply with quote

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?
herby handcock
Guest







RE string within string
PostPosted: Thu Jul 29, 2004 5:52 am     Reply with quote

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?
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Jul 29, 2004 8:20 am     Reply with quote

Try the string function strstr().

ptr = strstr(s1, s2) - Search for s2 in s1.
Ttelmah
Guest







PostPosted: Thu Jul 29, 2004 9:05 am     Reply with quote

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
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Jul 29, 2004 10:54 am     Reply with quote

DOH! I guess it would help to read through ALL of the text first, eh? *smacks forehead*
Ttelmah
Guest







PostPosted: Thu Jul 29, 2004 10:59 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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