FIRMWARE DEVELOPER
Embedded Systems

Write C code to implement the strstr() function to search for a substring

Did you know now you can instantly catch up with your essential programming tools such as emulators and IDE`s on any device(PC/Mac/android/iOS) to remotely access your programming/testing work on high performance citrix vdi from CloudDesktopOnline. To know more about dedicated server, try out dedicated gpu server hosting from one of the leading cloud hosting providers – Apps4Rent.

Question :- Write C code to implement the strstr() function to search for a substring

Synopsis:

 

Description:

The strstr function locates the first occurrence of the string string1 in the string string2 and returns a pointer to the beginning of the first occurrence.

Return Value

The strstr function returns a pointer within string2 that points to a string identical to string1. If no such sub string exists in source string a null pointer is returned.

C code to implement the strstr() function

 

 

Output

Write C code to implement the strstr() function to search for a substring

Suggested Reading

  1. Write a C program to reverse the words in a sentence in place
  2. Write your own trim() or squeeze() function to remove the spaces from a string
  3. Write a C program which does wildcard pattern matching algorithm