About strchr ()

Source: Internet
Author: User

Recently, this function is used to construct a binary tree based on the forward and middle orders, but this function is not good because strchr returns a character in the string.First timeIf there are repeated characters, it will be white blind. SoThe premise is that there are no repeated elements in the binary tree..

 

Header file: # include <cstring> (C ++) or # include <string. h> (c)

Function: locate the first occurrence of character C in string S.

Note: return the pointer at the first occurrence of C. If C does not exist in S, return null.

 

C ++Program:

# include <iostream> </P> <p> # include <cstring> </P> <p> using namespace STD; </P> <p> int main () </P> <p >{</P> <p> char STR [6] = {'I ', 'l', 'O', 'V', 'E', 'U'}; </P> <p> char C; </P> <p> while (CIN> C) <br/>{</P> <p> char * TMP = strchr (STR, C ); // returns the pointer of 'v' in STR </P> <p> If (TMP! = NULL) </P> <p> cout <* TMP <Endl; </P> <p> else </P> <p> cout <"null" <Endl; </P> <p >}</P> <p> return 0; </P> <p >}</P> <p>

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.