C language Strstr () function: Returns the address of the first occurrence of a substring in a string

Source: Internet
Author: User

and today I learned a function.header files: #include <string.h>

The Strstr () function is used to retrieve the first occurrence of a substring in a string, with the following prototype:
Char *strstr (char *str, char * substr);

"Parameter description" STR is the string to retrieve, substr is the substring to retrieve.

Return value returns the address of the first substring substr in STR, or null if no substring is retrieved.

The use of the function example Strstr () function.

#include <stdio.h> #include <string.h>int main () {    //can also be changed to char str[] = "http://see.xidian.edu.cn/cpp/u /xitong/";    Char *str = "http://see.xidian.edu.cn/cpp/u/xitong/";    Char *substr = "See";    Char *s = strstr (str, substr);    printf ("%s\n", s);    return 0;}

Operation Result:
see.xidian.edu.cn/cpp/u/xitong/

This function is used in question 1238.

C language Strstr () function: Returns the address of the first occurrence of a substring in a string

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.