Strsep () function

Source: Internet
Author: User

Prototype: char * strsep (char ** stringp, const char * delim );

Function: Splits a string into a group of strings. Scan backward from the position pointed to by stringp. If a character pointing to a location by delim is encountered, replace the character with null and return the address pointed to by stringp.

Strsep function, which is not supported in Windows Dev-C ++. This function is often used to write UNIX analysis strings. You can use man strsep to see how to use strsep, suppose we want to analyzeURLGet string: user_command = appleboy & test = 1 & Test2 = 2. You can use the strsep function twice to separate all strings and obtain individual names and values. Strsep (stringp, delim) the first parameter is passed into the string to be analyzed, and the second parameter is passed into the delim symbol. If stringp is a null string, the function will return NULL. In other words, strsep will find the first delim symbol in the stringp string, replace it with the \ 0 symbol, and then update stringp to the next string of the \ 0 symbol, strsep () function returns the original stringp indicator.

Example:

# Include <string. h>
# Include <stdlib. h>
Int main ()
{
Char PTR [] = {"abcdefghijklmnopqrstuvwxyz "};
Char * P, * STR = "M ";
P = PTR;
Printf ("% s \ n", strsep (& P, STR ));
Printf ("% s \ n", P );
STR = "S ";
Printf ("% s \ n", strsep (& P, STR ));
Printf ("% s \ n", P );

}

[Root @ shwhg test] # GCC test131.c
[Root @ shwhg test] #./A. Out
Abcdefghijkl
Nopqrstuvwxyz
Nopqr
Tuvwxyz

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.