Q22.Write a code to check whether the string is substring of given string or not.

String :- The string is defined as an array of characters. The difference between a character array and a string is the string ending with a special character ‘\0’.Given two strings S1 and S2, The task is to find if S1 is a substring of S2. If yes, return the index of the first occurrence, else return -1.

For Example :- Input : s1 = “Alfa”, s2 = “Alfatechlab”
Output : 0

check whether substring in a string Algorithm 

START

STOP

check whether substring in a string code

Output

Substring Found Successfully!

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number