Question 559: Which of the following function is used to find the first occurrence of a given string in another string?
tcs
wipro
infosys
general
aptitude
strings
The functionstrstr()Finds the first occurrence of a substring in another stringDeclaration: char *strstr(const char *s1, const char *s2);Return Value:On success,strstrreturns a pointer to the element ins1wheres2begins (points tos2ins1).On error (ifs2does not occur ins1),strstrreturns null.Example:#include <stdio.h> #include <string.h> int main(void) { char *str1 = "IndiaBIX", *str2 = "ia", *ptr; ptr = strstr(str1, str2); printf("The substring is: %s\n", ptr); return 0; }Output: The substring is: iaBIX