STRCHR () function and STRRCHR () function

Source: Internet
Author: User

Strchr

defined in header file <string.h>
Char *strchr (const char *STR, int ch);
look for the first occurrence of CH (converted to char as (char) ch) in the null-terminated byte string pointed to by STR (each character is considered to be a unsigned char). The terminating null character is considered to be part of the string and can be found when searching for ' + '.
If STR is not a pointer to a null-terminated byte string, the behavior is undefined.
Parameters
STR-pointer to the null-terminated byte string to be parsed
CH-the character to find
return value
A pointer to the character found by STR, which returns a null pointer when the word is not found.
Example

/* STRCHR Example */#include <stdio.h> #include <string.h>int main () {  char str[] = "This is a sample Strin G ";  char * PCH;  printf ("Looking for the ' s ' character in \"%s\ "... \ n", str);  PCH=STRCHR (str, ' s ');  while (Pch!=null)  {    printf ("found at%d\n", pch-str+1);    PCH=STRCHR (pch+1, ' s ');  }  return 0;}




Found at 18*/

Strrchr 

Defined in header file <string.h>
const char *STRRCHR (const char *STR, int ch);
Char *strrchr (char *str, int ch);
Find the last occurrence of the character ch in the byte string pointed to by Str.

Parameters
Str-null a pointer to the end of a byte string for analysis

CH-Search Characters

return value
STR, or NULL to find a pointer to the character if no such character is found

Example

/* STRRCHR Example */#include <stdio.h> #include <string.h>int main () {  char str[] = "This is a sample stri Ng ";  char * PCH;  PCH=STRRCHR (str, ' s ');  printf ("Last occurence of ' s ' found at%d \ n", pch-str+1);  return 0;} /*last occurence of ' s ' found at 18 * *

  

STRCHR () function and STRRCHR () function

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.