77

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!

0

2 Answers 2

132
if (strstr(request, "favicon") != NULL) {
    // contains
}
Sign up to request clarification or add additional context in comments.

3 Comments

Is it bad style to omit != NULL ?
don't forget to #include <string.h>
@user1011471 Personally I always prefer to be explicit. That way there's never any confusion.
23
strstr(request, "favicon") != NULL

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.