Simple way to check if a string contains another string in C?

CStringSubstring

C Problem Overview


I'm pretty new to the language. Let's say I have a string from an HTTP request, such as

char * request = "GET /favicon.ico HTTP/1.1";

And I specifically want to know if favicon is in that request, perhaps with a boolean value. What is a relatively simple way to go about this? I know how to do it in Java, but I'm more lost with C.

Thanks!

C Solutions


Solution 1 - C

if (strstr(request, "favicon") != NULL) {
    // contains
}

Solution 2 - C

strstr(request, "favicon") != NULL

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioniaacpView Question on Stackoverflow
Solution 1 - Cuser529758View Answer on Stackoverflow
Solution 2 - CFred FooView Answer on Stackoverflow