Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

searching substrings in char array [duplicate]

Tags:

c++

As I know there is a function in C++ string which performs substring search: string1.find(string2).

Is there any way to perform the same action in char? Below is my question:

    #include <iostream>
    #include <cstring>
    using namespace std;
    int main()
    { 
      char a[]="hello world!";
      char b[]="el";
      //find substring b[] in a[]


    }

let's say i need to find substring "el" in the string, is it possible to do that?

like image 996
user3113716 Avatar asked Dec 18 '13 03:12

user3113716


1 Answers

char *output = NULL;
output = strstr (a,b);
if(output) {
    printf("String Found");
}
like image 127
Elixir Techne Avatar answered Sep 21 '22 07:09

Elixir Techne