0

Exists in C method for finding a substring in a string?

If not, how to effectively deal with this problem?

In for cycle? And what is the correct syntax in c?

const char subString[] = { "car", "blue", "red"};
char String[] = "I love red color and i hate blue color";

for .... String lenght... {

      printf("I found subString");

}
1
  • 1
    const char subString[] = { "car", "blue", "red"}; won't compile, const char * subString[] = { "car", "blue", "red"};would. Commented Nov 9, 2013 at 21:31

1 Answer 1

5

For null terminated C strings:

strstr()

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, i try to use your strstr, but how can i work with this string? string = "Madam, I am Adam"; i want find subString = Adam... thank you
If you know, that the word of interest is enclosed with spaces, search for " Adam" and skip that space afterwards. You might have seen my answers regarding tokenization, but everything has been deleted. You may rephrase your question or add a new question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.