Implement strstr() to find a substring in a string

Write C code to implement the strstr (Search for a substring) function. Do not use any system library such as strlen.

Sponsored: has published a chatbot, who can chat with you and help you find apartments in San Francisco and Bay area. Check it out:

01 int strstr(char* s, char* p)
02 {
03     int fast=0;
04     int slow=0;
05     int j=0;
06     while(s[fast]!=){
07         if(s[fast++]==p[j++])
08             ;
09         else{
10             slow++;
11             fast=slow;
12             j=0;
13         }
14         if(p[j]==)
15             return slow;
16     }
17     return 1;
18 }
This entry was posted in String, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s