C strstr Function

The C strstr function is a String Function, which returns a pointer to the first occurrence of a string in the given string. The syntax of the strstr in C Programming language is

void *strstr(const char *str, const char *str_to_look);
  • str: A valid string
  • str_to_look: Text that you want to search inside str

strstr in C Language Example

The strstr function used to search for the first occurrence of a substring within the user specified string.

You have to include the #include<string.h> header before using this Function. This program will help you to understand the strstr with multiple examples using If else Statement. Here, if a pointer to the given substring found, then statements inside the if block will print otherwise, else block statements will print by C Programming.

#include <stdio.h> 

int main()
    char str[] =  "This is abc working in abc Company";
    char *res;
    res = strstr(str, "abc");
        printf("We Found your String");
        printf("\nThe Final String From 'abc' is : %s \n", res);
        printf("String Not found. Sorry!! \n");
    return 0;
C strstr function example