hi all,
i am writing a program in which i am checking if a string contains another string(same what strstr does).
i assumed intially that the string1 is a long string with spaces and string2 is a word(which might be or might not be present in string1)
i have used strtok to seperate the words in string1 to be checked using strcmp.
its a very simple logic, but the problem is its showing segmentation fault.
can anyone find me a solution.
rati 0 Junior Poster in Training
Recommended Answers
Jump to Poststrtok() is not what you want. The text in string2 may or may not be a complete word surrounded with spaces. It could be a few letters of some larger word. Better if you just search string1 for the first character of string2. When (and if) found check if the …
Jump to Post>its a very simple logic
You'd think, but that might not be the case.>but the problem is its showing segmentation fault.
I'd wager my next pay check that you're trying to strtok a string literal.
Jump to Post>i am new to it, if you could please be a bit kind not to use those words for my code
We're not going to blow sunshine up your butt just because you're new. Eventually someone is going to tell you that you're a bad programmer, and it's better that …
All 12 Replies

iamthwee
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Narue 5,707 Bad Cop Team Colleague
rati 0 Junior Poster in Training
rati 0 Junior Poster in Training
Salem 5,265 Posting Sage
rati 0 Junior Poster in Training
John A 1,896 Vampirical Lurker Team Colleague
rati 0 Junior Poster in Training
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
Narue 5,707 Bad Cop Team Colleague
rati 0 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.