How to capture a specified character from a specified character in a string (pointer )? (C/C ++) (c)

Source: Internet
Author: User

Abstract
This is a common function in practice. Unfortunately, it is a string in C. h does not provide this function. In this article, a small function is implemented to this function and matched with pointer.

Introduction
How can I capture a specified character from a string? (C/C ++) (c), which can already contain 99% of requirements. The only defect is that string. most of the letters in H are returned to the char * of the callback. If you want to upgrade the function, use the string. h. For the original function, the vertex must provide the pointer function.

Both the third and fourth regions use char *‧

Strchrp. C/C

1 /*  
2 (C) oomusou 2009 Http://oomusou.cnblogs.com
3
4 Filename: strchrp. c
5 Compiler: Visual C + + 9.0
6 Description: Demo how to get string from specify Char to Char (pointer ver .)
7 Release: 04/26/2009 1.0
8 */
9
10 # Include < Stdio. h >
11 # Include < String . H >
12
13 Void Strchrp ( Char   * DeST, Char   * SRC, Char   * Begin, Char   * End ){
14 Int Len = Strlen (BEGIN) - Strlen (end );
15 Strncpy (DEST, begin, Len );
16 Dest [Len] =   ' \ 0 ' ;
17 }
18
19 Int Main (){
20 Char SRC [] =   " [10, 20] " ;
21 Char Dest [ 20 ];
22
23 Strchrp (DEST, SRC, strchr (SRC, ' , ' ) + 1 , Strchr (SRC, ' ] ' ));
24
25 Printf ( " % S " , DEST );
26 }

Results

20

Known Issue
In this version, when begin and end are null, the attacker will be generated and a better anti-stay mechanism is required ‧

Download the complete program
Strchrp.7z

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.