Home  >  Article  >  Backend Development  >  What is the usage of strstr function in C language?

What is the usage of strstr function in C language?

烟雨青岚
烟雨青岚Original
2020-07-06 11:25:299106browse

The "strstr(str1,str2)" function in the C language is used to determine whether the string "str2" is a substring of "str1"; if so, the function returns "str2" in "str1" The address of the first occurrence; otherwise NULL is returned. Its syntax is "* strstr(str1,str2)".

What is the usage of strstr function in C language?

strstr(str1,str2) function is used to determine whether the string str2 is a substring of str1. If so, the function returns the address of the first occurrence of str2 in str1; otherwise, NULL is returned.

C Language

Included file: string.h

Function name: strstr

Function prototype:

extern char *strstr(char *str1, const char *str2);

Syntax:

* strstr(str1,str2)

str1: The target to be searched string expression to search.

str2: The object to be searched The string expression to find.

Return value: If str2 is a substring of str1, return the address of the first occurrence of str2 in str1; if str2 is not a substring of str1, return NULL.

Example:

char str[]="1234xyz";
char *str1=strstr(str,"34");
cout << str1 << endl;

displays: 34xyz

Recommended tutorial: "C Language"

The above is the detailed content of What is the usage of strstr function in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn