Algorithm:
Step 1: start
Step 2: read the string and then displayed
Step 3: read the string to be searched and then displayed
Step 4: searching the string T in string S and then perform the following
steps
i. found=strstr(S,T)
ii. if found print the second string is found in the first string at the position. If not goto step 5
Step 5: print the -1
Step 6: stop
Output:
1.enter the first string: kali
Enter the string to be seareched: li
second string is found in the first string at 2 position
2.enter the first string:
nagaraju
Enter the string to be seareched:
raju
second string is found in the first string at 4 position 3.enter the first string:
nagarjuna
Enter the string to be seareched: ma
-1
Conclusion: The program is error free
VIVA QUESTIONS:
1) What is the difference between printf() and puts() ?
Ans: puts() is used to display the string at a time and it doesn’t take any integers values but printf() takes any values as defined by the user
2) define pointer variable ?
Ans: pointer variables are defined as variable that contain the memory addresses of data or executable code.
3) What is use of the strcmp() function ?
Ans: This function compares two strings character by character and returns a value 0 if both strings are equal and non zero value if the strings are different.
No comments:
Post a Comment