LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 08-14-2008, 04:17 PM   #1
cleopard
Member
 
Registered: May 2006
Posts: 39

Rep: Reputation: 15
searching for char string containing a '/'


I have a C program and there's a place where I have a constant string that contains a '/', such as

char str[] = "</script>";

One line of code uses a call to 'strstr' to look for this constant within a larger string. Running my program inside of 'ddd', I see the large string contains the above constant, but the call fails. I thought I might need to include a backslash in front of the forward slash to let it know I mean that particular character, and not some other use. Is there some other kind of modification I need to make to the above constant? Thank you.
 
Old 08-14-2008, 04:21 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Can you post the tokenizing segment of your code? Have you tried strsep instead?
ta0kira

edit:
Sorry, read too fast. I thought you were using strtok for some reason. Please post the relevant code, anyway. Thanks.

Last edited by ta0kira; 08-14-2008 at 04:23 PM.
 
Old 08-14-2008, 04:33 PM   #3
cleopard
Member
 
Registered: May 2006
Posts: 39

Original Poster
Rep: Reputation: 15
if ((end_ptr = strstr(tmp_ptr, end_tag)) == NULL)
.
.
.


'end_tag' is the string set to "</script>", which is located in several characters down from the beginning of 'tmp_str', but it's not found.
 
Old 08-14-2008, 05:17 PM   #4
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
Does your string buffer contain null characters?
strstr will only read up to the first null character.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get first char of a string? raskol Programming 2 04-05-2008 07:11 PM
[] string.spits(char) in C++ manolakis Programming 2 09-24-2007 10:05 AM
Converting string to char xfceslacker Programming 2 10-20-2006 06:15 PM
prepend char to a string schneidz Programming 6 06-01-2005 09:53 AM
Convert C++ string to C char* nyk Programming 3 06-17-2004 09:15 AM


All times are GMT -5. The time now is 05:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration