char *p; p = (char*) malloc(100);
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 = "CuriousTab", *str2 = "ia", *ptr;
ptr = strstr(str1, str2);
printf("The substring is: %s\n", ptr);
return 0;
}
Output: The substring is: iaCURIOUSTAB
It scans a string s in the reverse direction, looking for a specific character c.
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char text[] = "I learn through CuriousTab.com";
char *ptr, c = 'i';
ptr = strrchr(text, c);
if (ptr)
printf("The position of '%c' is: %d\n", c, ptr-text);
else
printf("The character was not found\n");
return 0;
}
Output:
The position of 'i' is: 19
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.