strstr() Find Substring
#include <string.h> Required for declarations only
char *strstr(string1,string2);
char *string1; String to search
char *string2; Substring to search for
strstr() returns a pointer to the first occurrence of 'string2' in
'string1'.
Returns: A pointer to the first occurrence of 'string2' in
'string1'. NULL is returned if 'string2' is not found.
-------------------------------- Example ---------------------------------
The following statements search for 'str2' in 'str1'.
#include <string.h>
#include <stdio.h>
char *str1 = "An ounce of prevention";
char *str2 = "ounce";
char *substr;
main()
{
substr = strstr(str1,str2);
if (substr != NULL)
printf("%s",substr);
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster