The advantages are:
1. You can define multiple separators at once. When the function is executed, it is cut by a single delimiter rather than by the entire delimiter, while the explode is cut by the entire separator string. As a result, explode can be cut in Chinese, and strtok is not, will be garbled.
2. When using the while or for mate Strtok () traversal, you can change the delimiter at any time, or you
Alibaba interview questions: implement the Char ** StrToK (const char * S1, const char * S2) function, Alibaba strtok
Implementation function: Char ** StrToK (const char * S1, const char * S2)
Function: After S2 truncates the S1 string, It outputs the truncated string. For example, S1 = abcdefg, S2 = be, returns the three strings a, cd, and fg with a pointer to t
Prototype: extern char * strtok (char * s, char * delim );
Usage: # include
Function: Splits a string into a group of tag strings. S is the string to be decomposed, and delim is the separator string.
NOTE: For the first call, s must point to the string to be decomposed, and then the call should set S to null.Strtok searches for characters contained in delim in S and replaces them with null ('\ 0') until the entire string is searched.Returns the strin
The following illustration is taken from the latest Linux kernel 2.6.29, indicating that the strtok () function is no longer used, instead of strsep (), which is faster.
/**Linux/lib/string. c** Copyright (c) 1991,199 2 LinusTorvalds*//** Stupid Library Routines .. the optimized versionsShoshould generally be found* As Inline code in** These are buggy as well ..*** Fri Jun25 1999, Ingo oeser *-Added strsep ()Which will replace
Document directory
1. One application instance
2. strtok_r and Its Usage
3. Source Code of strtok and strtok_r
(1) I have introduced some precautions for using the strtok function. This article introduces an application of strtok and introduces the strtok_r function.
1. One application instance
A classic example on the network is to split strings and store
Strtok and strtok_r
Prototype: char * strtok (char * s, char * delim );Function: Splits a string into a group of strings. S is the string to be decomposed, and delim is the separator string.Note: during the first call, s points to the string to be decomposed, and then calls it again to set S to null.Strtok searches for characters included in delim in S and replaces them with null ('/0') until the e
Strtok and Strtok_r
Prototype: Char *strtok (char *s, char *delim);Function: Decomposes a string into a set of strings. S is the string to be decomposed, Delim is the delimiter string.Description: On first call, S points to the string to be decomposed, and then calls to set S to null.Strtok finds the characters included in the Delim in S and replaces them with null ('/0 ') until the entire stri
Turn from: http://blog.csdn.net/helpxs/article/details/6959057
(i) has introduced the use of strtok functions of some considerations, this article will introduce a strtok application and draw out the Strtok_r function.
1. An application example
A classic example on the web is to split the string into the structure. For example, an existing structural body
typedef struct person{Char name[25];Char sex[10];Cha
Strtok and strtok_r
Prototype: char * strtok (char * s, char * delim );Function: Splits a string into a group of strings. S is the string to be decomposed, and delim is the separator string.Note: during the first call, s points to the string to be decomposed, and then calls it again to set S to null.Strtok searches for characters included in delim in S and replaces them with null ('/0') until the e
Function Name: strtokFunction: searches for words separated by the delimiters specified in the second string.Usage: char * strtok (char * str1, char * str2 );Program example:# Include # Include Int main (void){Char input [16] = "abc, d ";Char * p;/* Strtok places a NULL terminatorIn front of the token, if found */P = strtok (input ,",");If (p) printf ("% s/n", p
Copyright NOTICE: This article is the original article, without the owner's permission to reprint.
Directory (?) [+]Considerations for the use of Strtok functions 1. Function prototype and its basic application The Strtok function is used to decompose a string, and its prototype is: [CPP]View Plain Copy char *strtok (char str[], const char *delim);Where Str is t
[Switch] multi-layer string cutting in C Language (how to use strtok_r strtok) and strtok_rstrtok
[Switch] multi-layer string cutting in C Language (how to use strtok_r strtok)
This article mainly introduces the method of multi-layer string cutting in C language, introduces the weakness of strtok, and uses the strtok_r method.
Address: http://www.jb51.net/article
The strtok () function should have been encountered by everyone, but it seems that there are always some problems. Here we will focus on it.
First, let's take a look at the explanations on msdn:
Char * strtok (char * strtoken, const char * strdelimit );Parameters
Strtoken
String containing token or tokens.
Strdelimit
Set of delimiter characters.
Return Value
Returns a pointer t
1. Strtok Introduction
As is known to all, Strtok can be based on the user-supplied delimiter (which can also be plural for example). ”)Splits a section of string until it encounters a "yes".
For example, the delimiter = "," string = "Fred,john,ann"
by Strtok, 3 strings of "Fred" "John" "Ann" can be extracted.
The C code above is
Copy Code code as fol
PHP strtok () function instance application. Compared with explode (), the strtok () function can control the pace. Cut strings as needed. The advantage is: 1. Multiple separators can be defined at a time. When a function is executed, the strtok () function can control the pace compared to explode () by a single separator. Cut strings as needed. Its advantages ar
Function prototype: char * strtok (char * s, char * delim );
Function: splits string s by string delim and returns the split result.
Function usage:
1. The essence of the strtok function is that strtok searches for characters contained in delim in S and replaces them with null ('/0') until the entire string is searched. This statement has two meanings: (1) each t
So the correct application of the method we will be in this article for you to explain in detail, hope to be helpful to everyone, improve the actual program development efficiency.
C + + Strtok prototype is as follows:
Char *strtok (
Char *strtoken,
const char *strdelimit);
Crt_strtok.c
/**//* in this program, a loop uses strtok
* To print all the tokens (
Char * strtok (char * string, const char * delimiters );
Sequentially truncate string if Delimiter is found.If string is notNull, The function scans string for the first occurrence of any character defined ded in delimiters. if it is found, the function overwrites the delimiter in string by a null-character and returns a pointer to the token, I. e. the part of the scanned string previous to the delimiter.After a first callStrtok, The function may be
Compared with explode (), the strtok () function can control the pace. Cut strings as needed. When a function is executed, it is cut by a single separator rather than the entire separator, while explode is cut by the entire separator string. Therefore, explode can be cut in Chinese, while strto
Compared with explode (), the strtok () function can control the pace. Cut strings as needed. Its advantages are:
The Strtok () function can control the rhythm relative to explode (). Cut strings on demand. The advantages are:
1. You can define multiple separators at once. When the function is executed, it is cut by a single delimiter rather than by the entire delimiter, while the explode is cut by the entire separator string. As a result, explode can be cut in Chinese, and strtok is not, will be garbled.
2. When using
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.