C Programming - Strings - Discussion
Discussion Forum : Strings - General Questions (Q.No. 5)
5.
Which of the following function is used to find the first occurrence of a given string in another string?
Answer: Option
Explanation:
The function strstr() Finds the first occurrence of a substring in another string
Declaration: char *strstr(const char *s1, const char *s2);
Return Value:
On success, strstr returns a pointer to the element in s1 where s2 begins (points to s2 in s1).
On error (if s2 does not occur in s1), strstr returns 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
Discussion:
10 comments Page 1 of 1.
Rakhi Kirtankar said:
6 years ago
Strstr function finds one string in another string. And when it finds the second string it prints that substring along with the remaining character. And pointer is used for storing returned address
(1)
Arun said:
6 years ago
How could we solve the program without using strstr fuctions?
(1)
Surbhi said:
7 years ago
char *strstr(const char * string, const char* substr).
It will return a pointer to the first occurrence of sub string thus will act as character array.
It will return a pointer to the first occurrence of sub string thus will act as character array.
(1)
Ramya said:
7 years ago
How it prints "iabix". Can someone explain clearly?
(1)
Nikhil said:
9 years ago
ia search in indiabix string from ia it will print reaming print iabix.
(1)
Kd said:
9 years ago
How can we say that output is a BIX, because there already given strr1 = IndiaBix. How it's possible?
Manisha said:
1 decade ago
This function finds the second string matches with the first string it returns to pointer location otherwise 0.
Srinivas said:
1 decade ago
The strstr() function finds the first occurrence of the substring in given string.
So it will return the pointer(Address) where there is matching of substring occurs.
So it will return the pointer(Address) where there is matching of substring occurs.
Nancy said:
1 decade ago
How iaBIX s output what happen to india how strstr() removes india.??
Jalal said:
1 decade ago
Why use pointer function?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers