The C language finds the string and returns the index

Source: Internet
Author: User

The C language itself does not have a function to find a string and return an index, although it is easier to say that you can get an index by writing a lookup function.

C language has a strchr function to find the first position of the character, the key is this function, if used skillfully, you can also get the index of the found string

1     char *str_1 = "wtwq211"; 2     char *str_2 = STRCHR (str_1, ' Q '); 3     printf ("%s\n", str_2); 4 5     int index= Str_2-str_1;6     printf ("%c\n", Str_1[index]);       

The C language finds the string and returns the index

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.