strtok函数C元素被视为问题

huangapple go评论56阅读模式
英文:

strtok function c element considered problem

问题

当我尝试使用分隔符拆分字符串时,strtok 函数不会考虑空字符串,我想知道如何修复它。
例如,在我的情况下,我需要拆分像 "a-b-c" 这样的字符串。当我尝试拆分字符串 "a--b-c" 时,结果应该是 "a""""b""c"(注意空字符串)。但如果我在调用函数后打印每个元素的结果,它只考虑 "a""b""c"。为什么会发生这种情况,我该如何修复它?

char str[] = "a--b-c";
char *delim = "-";
char *token;

token = strtok(str, delim);

while (token != NULL) {
    printf("element is: =====%s===== \n ", token);
    token = strtok(NULL, delim);
}

打印出的元素应该有4个(a、空字符串、bc),但使用这段代码,只有3个(abc)。

英文:

When I try to split a string with a delimiter, the strtok function doesn't consider empty strings and I would like to know how to fix it.
For example, in my case, I have to split strings like "a-b-c". When I try to split the string "a--b-c", the result should be "a", "", "b", "c" (note the empty string). But if I print the result of each element after calling the function, it only considers "a", "b", and "c". Why does this happen, and how can I fix it?

    char str[] = "a--b-c";
    char *delim = "-";
    char *token;

    token = strtok(str, delim);

    while (token != NULL) {
        printf("element is: =====%s===== \n ", token);
        token = strtok(NULL, delim);
    }

Elements printed should be 4 (a, empty string, b, c) but with this code, it's only 3 (a, b, c).

答案1

得分: 5

根据C标准,strtok()的第一步是

在指向s1的字符串中查找第一个不包含在指向s2的当前分隔符字符串中的字符。

如果你想要不同的行为,你需要编写自己的函数来实现你想要的功能。

英文:

According to the C standard, the first action of strtok() is that it

> searches the string pointed to by s1 for the first character that is not
contained in the current separator string pointed to by s2.

If you want different behaviour, you'll need to write your own function that does what you want.

答案2

得分: 3

以下是翻译好的部分:

函数`strtok`搜索第一个不包含在当前分隔符字符串中的字符。因此,相邻的分隔符字符会被跳过。

此外,该函数会更改源字符串。

您可以使用另一个字符串函数,例如`strcspn`,而不是使用`strtok`。

以下是演示程序。

#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[] = "a--b-c";
    const char *delim = "-";

    for (char *p = str; *p != '
函数`strtok`搜索第一个不包含在当前分隔符字符串中的字符。因此,相邻的分隔符字符会被跳过。

此外,该函数会更改源字符串。

您可以使用另一个字符串函数,例如`strcspn`,而不是使用`strtok`。

以下是演示程序。

#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[] = "a--b-c";
    const char *delim = "-";

    for (char *p = str; *p != '\0'; )
    {
        size_t n = strcspn(p, delim);

        printf("\"%.*s\"\n", (int)n, p);

        if (*(p += n) != '\0') ++p;
    }
}
'
; )
{ size_t n = strcspn(p, delim); printf("\"%.*s\"\n", (int)n, p); if (*(p += n) != '
函数`strtok`搜索第一个不包含在当前分隔符字符串中的字符。因此,相邻的分隔符字符会被跳过。

此外,该函数会更改源字符串。

您可以使用另一个字符串函数,例如`strcspn`,而不是使用`strtok`。

以下是演示程序。

#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[] = "a--b-c";
    const char *delim = "-";

    for (char *p = str; *p != '\0'; )
    {
        size_t n = strcspn(p, delim);

        printf("\"%.*s\"\n", (int)n, p);

        if (*(p += n) != '\0') ++p;
    }
}
'
) ++p;
} }

程序输出如下:

"a"
""
"b"
"c"

如果对于像"-"这样的字符串,您需要输出两个子字符串,如下所示:

""
""

或者对于像"a--b-c-"这样的字符串,您需要输出:

"a"
""
"b"
"c"
""

那么只需在程序中进行以下小的更改即可:

#include <stdio.h>
#include <string.h>

int main(void)
{
char str[] = "a--b-c-";
const char *delim = "-";

for (char *p = str; *p != '
for (char *p = str; *p != '\0'; )
{
size_t n = strcspn(p, delim);
printf("\"%.*s\"\n", (int)n, p);
if (*(p += n) != '\0')
{
if (*++p == '\0')
{
printf("\"%s\"\n", p);
}
}
}
'; ) { size_t n = strcspn(p, delim); printf("\"%.*s\"\n", (int)n, p); if (*(p += n) != '
for (char *p = str; *p != '\0'; )
{
size_t n = strcspn(p, delim);
printf("\"%.*s\"\n", (int)n, p);
if (*(p += n) != '\0')
{
if (*++p == '\0')
{
printf("\"%s\"\n", p);
}
}
}
') { if (*++p == '
for (char *p = str; *p != '\0'; )
{
size_t n = strcspn(p, delim);
printf("\"%.*s\"\n", (int)n, p);
if (*(p += n) != '\0')
{
if (*++p == '\0')
{
printf("\"%s\"\n", p);
}
}
}
') { printf("\"%s\"\n", p); } } }

}


在这种情况下,程序的输出是:

"a"
""
"b"
"c"
""


对于由指针`p`指向的每个获得的子字符串,长度为`n`,您可以定义一个变量长度的字符数组或动态分配一个字符数组,然后将子字符串复制到数组中,如果需要的话。例如:

#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[] = "a--b-c";
    const char *delim = "-";

    for (char *p = str; *p != '

对于由指针`p`指向的每个获得的子字符串,长度为`n`,您可以定义一个变量长度的字符数组或动态分配一个字符数组,然后将子字符串复制到数组中,如果需要的话。例如:
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[] = "a--b-c";
const char *delim = "-";
for (char *p = str; *p != '\0'; )
{
size_t n = strcspn(p, delim);
char substr[n + 1];
memcpy(substr, p, n);
substr[n] = '\0';
printf("\"%s\"\n", substr);
if (*(p += n) != '\0') ++p;
}
}
'; ) { size_t n = strcspn(p, delim); char substr[n + 1]; memcpy(substr, p, n); substr[n] = '

对于由指针`p`指向的每个获得的子字符串,长度为`n`,您可以定义一个变量长度的字符数组或动态分配一个字符数组,然后将子字符串复制到数组中,如果需要的话。例如:
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[] = "a--b-c";
const char *delim = "-";
for (char *p = str; *p != '\0'; )
{
size_t n = strcspn(p, delim);
char substr[n + 1];
memcpy(substr, p, n);
substr[n] = '\0';
printf("\"%s\"\n", substr);
if (*(p += n) != '\0') ++p;
}
}
'; printf("\"%s\"\n", substr); if (*(p += n) != '

对于由指针`p`指向的每个获得的子字符串,长度为`n`,您可以定义一个变量长度的字符数组或动态分配一个字符数组,然后将子字符串复制到数组中,如果需要的话。例如:
#include <stdio.h>
#include <string.h>
int main(void)
{
char str[] = "a--b-c";
const char *delim = "-";
for (char *p = str; *p != '\0'; )
{
size_t n = strcspn(p, delim);
char substr[n + 1];
memcpy(substr, p, n);
substr[n] = '\0';
printf("\"%s\"\n", substr);
if (*(p += n) != '\0') ++p;
}
}
') ++p; } }
英文:

The function strtok searches for the first character that is not contained in the current separator string. So adjacent separator characters are skipped.

Also the function changes the source string.

Instead of using strtok you can use another string function as for example strcspn.

Here is a demonstration program.

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

int main( void )
{
	char str[] = &quot;a--b-c&quot;;
	const char *delim = &quot;-&quot;;

	for (char *p = str; *p != &#39;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main( void )
{
char str[] = &quot;a--b-c&quot;;
const char *delim = &quot;-&quot;;
for (char *p = str; *p != &#39;\0&#39;; )
{
size_t n = strcspn( p, delim );
printf( &quot;\&quot;%.*s\&quot;\n&quot;, ( int )n, p );
if ( *( p += n ) != &#39;\0&#39;) ++p;
}
}
&#39;; ) { size_t n = strcspn( p, delim ); printf( &quot;\&quot;%.*s\&quot;\n&quot;, ( int )n, p ); if ( *( p += n ) != &#39;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main( void )
{
char str[] = &quot;a--b-c&quot;;
const char *delim = &quot;-&quot;;
for (char *p = str; *p != &#39;\0&#39;; )
{
size_t n = strcspn( p, delim );
printf( &quot;\&quot;%.*s\&quot;\n&quot;, ( int )n, p );
if ( *( p += n ) != &#39;\0&#39;) ++p;
}
}
&#39;) ++p; } }

The program output is

&quot;a&quot;
&quot;&quot;
&quot;b&quot;
&quot;c&quot;

If for a string like that &quot;-&quot; you need to output two substrings like

&quot;&quot;
&quot;&quot;

or for a string like that &quot;a--b-c-&quot; you need to output

&quot;a&quot;
&quot;&quot;
&quot;b&quot;
&quot;c&quot;
&quot;&quot;

then it is enough to make the following minor changes in the program

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

int main( void )
{
	char str[] = &quot;a--b-c-&quot;;
	const char *delim = &quot;-&quot;;

	for (char *p = str; *p != &#39;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main( void )
{
char str[] = &quot;a--b-c-&quot;;
const char *delim = &quot;-&quot;;
for (char *p = str; *p != &#39;\0&#39;; )
{
size_t n = strcspn( p, delim );
printf( &quot;\&quot;%.*s\&quot;\n&quot;, ( int )n, p );
if (*( p += n ) != &#39;\0&#39;)
{
if (*++p == &#39;\0&#39;)
{
printf( &quot;\&quot;%s\&quot;\n&quot;, p );
}
}
}
}
&#39;; ) { size_t n = strcspn( p, delim ); printf( &quot;\&quot;%.*s\&quot;\n&quot;, ( int )n, p ); if (*( p += n ) != &#39;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main( void )
{
char str[] = &quot;a--b-c-&quot;;
const char *delim = &quot;-&quot;;
for (char *p = str; *p != &#39;\0&#39;; )
{
size_t n = strcspn( p, delim );
printf( &quot;\&quot;%.*s\&quot;\n&quot;, ( int )n, p );
if (*( p += n ) != &#39;\0&#39;)
{
if (*++p == &#39;\0&#39;)
{
printf( &quot;\&quot;%s\&quot;\n&quot;, p );
}
}
}
}
&#39;) { if (*++p == &#39;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main( void )
{
char str[] = &quot;a--b-c-&quot;;
const char *delim = &quot;-&quot;;
for (char *p = str; *p != &#39;\0&#39;; )
{
size_t n = strcspn( p, delim );
printf( &quot;\&quot;%.*s\&quot;\n&quot;, ( int )n, p );
if (*( p += n ) != &#39;\0&#39;)
{
if (*++p == &#39;\0&#39;)
{
printf( &quot;\&quot;%s\&quot;\n&quot;, p );
}
}
}
}
&#39;) { printf( &quot;\&quot;%s\&quot;\n&quot;, p ); } } } }

The program output in this case is

&quot;a&quot;
&quot;&quot;
&quot;b&quot;
&quot;c&quot;
&quot;&quot;

For each gotten substring pointed to by the pointer p and with the length n you could either define a variable length character array or dynamically allocate a character array and then copy the substring in the array if it is required. For example

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

int main( void )
{
	char str[] = &quot;a--b-c&quot;;
	const char *delim = &quot;-&quot;;

	for (char *p = str; *p != &#39;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main( void )
{
char str[] = &quot;a--b-c&quot;;
const char *delim = &quot;-&quot;;
for (char *p = str; *p != &#39;\0&#39;; )
{
size_t n = strcspn( p, delim );
char substr[n + 1];
memcpy( substr, p, n );
substr[n] = &#39;\0&#39;;
printf( &quot;\&quot;%s\&quot;\n&quot;, substr );
if ( *( p += n ) != &#39;\0&#39;) ++p;
}
}
&#39;; ) { size_t n = strcspn( p, delim ); char substr[n + 1]; memcpy( substr, p, n ); substr[n] = &#39;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main( void )
{
char str[] = &quot;a--b-c&quot;;
const char *delim = &quot;-&quot;;
for (char *p = str; *p != &#39;\0&#39;; )
{
size_t n = strcspn( p, delim );
char substr[n + 1];
memcpy( substr, p, n );
substr[n] = &#39;\0&#39;;
printf( &quot;\&quot;%s\&quot;\n&quot;, substr );
if ( *( p += n ) != &#39;\0&#39;) ++p;
}
}
&#39;; printf( &quot;\&quot;%s\&quot;\n&quot;, substr ); if ( *( p += n ) != &#39;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
int main( void )
{
char str[] = &quot;a--b-c&quot;;
const char *delim = &quot;-&quot;;
for (char *p = str; *p != &#39;\0&#39;; )
{
size_t n = strcspn( p, delim );
char substr[n + 1];
memcpy( substr, p, n );
substr[n] = &#39;\0&#39;;
printf( &quot;\&quot;%s\&quot;\n&quot;, substr );
if ( *( p += n ) != &#39;\0&#39;) ++p;
}
}
&#39;) ++p; } }

答案3

得分: 1

strtok函数不会返回空令牌。如果你想改变这个行为,你需要编写自己的strtok函数,这并不难。下面是一个示例:

#include <stdio.h>
#include <string.h>

char *my_strtok(char *str, const char *delim)
{
    // 这个指针始终指向下一个要处理和返回的令牌,如果我们已经返回了最后一个令牌,则为NULL
    static char *next;

    char *p;

    if (str == NULL)
    {
        // 检查是否已经返回了最后一个令牌
        if (next == NULL)
        {
            // 在前一个函数调用中已经返回了最后一个令牌,因此返回NULL以表示没有更多的令牌
            return NULL;
        }

        // 下一个令牌可用,因此处理它
        str = next;
    }

    // 查找下一个分隔符字符
    p = strpbrk(str, delim);

    if (p == NULL)
    {
        // 这是最后一个令牌,因此记住没有更多的令牌
        next = NULL;
    }
    else
    {
        // 还有更多的令牌可用,因此在当前令牌的末尾写入一个空终止字符,并记住下一个令牌的起始位置
        *p = '
#include <stdio.h>
#include <string.h>

char *my_strtok(char *str, const char *delim)
{
    // 这个指针始终指向下一个要处理和返回的令牌,如果我们已经返回了最后一个令牌,则为NULL
    static char *next;

    char *p;

    if (str == NULL)
    {
        // 检查是否已经返回了最后一个令牌
        if (next == NULL)
        {
            // 在前一个函数调用中已经返回了最后一个令牌,因此返回NULL以表示没有更多的令牌
            return NULL;
        }

        // 下一个令牌可用,因此处理它
        str = next;
    }

    // 查找下一个分隔符字符
    p = strpbrk(str, delim);

    if (p == NULL)
    {
        // 这是最后一个令牌,因此记住没有更多的令牌
        next = NULL;
    }
    else
    {
        // 还有更多的令牌可用,因此在当前令牌的末尾写入一个空终止字符,并记住下一个令牌的起始位置
        *p = '\0';
        next = p + 1;
    }

    // 返回令牌
    return str;
}

int main(void)
{
    char str[] = "a--b-c";
    char *delim = "-";
    char *token;

    token = my_strtok(str, delim);

    while (token != NULL)
    {
        printf("Found token: \"%s\"\n", token);
        token = my_strtok(NULL, delim);
    }
}
'
;
next = p + 1; } // 返回令牌 return str; } int main(void) { char str[] = "a--b-c"; char *delim = "-"; char *token; token = my_strtok(str, delim); while (token != NULL) { printf("Found token: \"%s\"\n", token); token = my_strtok(NULL, delim); } }

这个程序的输出如下:

Found token: "a"
Found token: ""
Found token: "b"
Found token: "c"
英文:

The function strtok will not give you any empty tokens. If you want to change that behavior, you will have you write your own strtok function, which is not that hard. Here is an example:

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

char *my_strtok( char *str, const char *delim )
{
    //this pointer will always point to the next token to
    //be processed and returned, or NULL if we have already
    //returned the last token
    static char *next;

    char *p;

    if ( str == NULL )
    {
        //check whether we have already returned the last
        //token
        if ( next == NULL )
        {
            //we already returned the last token in a
            //previous function call, so return NULL to
            //indicate that there are no more tokens
            return NULL;
        }

        //the next token is available, so process it
        str = next;
    }

    //find the next delimiter character
    p = strpbrk( str, delim );

    if ( p == NULL )
    {
        //this is the last token, so remember that there are
        //no more tokens
        next = NULL;
    }
    else
    {
        //there are more tokens available, so write a null
        //terminating character at the end of the current
        //token and remember the start of the next token
        *p = &#39;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
char *my_strtok( char *str, const char *delim )
{
//this pointer will always point to the next token to
//be processed and returned, or NULL if we have already
//returned the last token
static char *next;
char *p;
if ( str == NULL )
{
//check whether we have already returned the last
//token
if ( next == NULL )
{
//we already returned the last token in a
//previous function call, so return NULL to
//indicate that there are no more tokens
return NULL;
}
//the next token is available, so process it
str = next;
}
//find the next delimiter character
p = strpbrk( str, delim );
if ( p == NULL )
{
//this is the last token, so remember that there are
//no more tokens
next = NULL;
}
else
{
//there are more tokens available, so write a null
//terminating character at the end of the current
//token and remember the start of the next token
*p = &#39;\0&#39;;
next = p + 1;
}
//return the token
return str;
}
int main( void )
{
char str[] = &quot;a--b-c&quot;;
char *delim = &quot;-&quot;;
char *token;
token = my_strtok(str, delim);
while ( token != NULL )
{
printf( &quot;Found token: \&quot;%s\&quot;\n&quot;, token );
token = my_strtok( NULL, delim );
}
}
&#39;; next = p + 1; } //return the token return str; } int main( void ) { char str[] = &quot;a--b-c&quot;; char *delim = &quot;-&quot;; char *token; token = my_strtok(str, delim); while ( token != NULL ) { printf( &quot;Found token: \&quot;%s\&quot;\n&quot;, token ); token = my_strtok( NULL, delim ); } }

This program has the following output:

Found token: &quot;a&quot;
Found token: &quot;&quot;
Found token: &quot;b&quot;
Found token: &quot;c&quot;

答案4

得分: 0

strtok 的工作方式与您期望的不同。该函数的规范很清楚:从分隔符字符串中的所有字符序列形成单个分隔符,并且初始和尾随的分隔符在不生成标记的情况下被消耗。因此,strtok() 从不生成空标记。

这样做的原因是该函数的最初目的:用空格分隔的单词。通过传递分隔符字符串 &quot; \t\f\r\n\v&quot; 来实现此目标,这样的行为更加直观,即将连续的空白字符视为单个分隔符。

您描述的行为对应于最初为BSD Unix变种开发的strsep() 函数,并且在包括Linux在内的大多数Unix平台上都可用。以下是手册页的摘要:

名称

strsep - 分离字符串

概要

#include <string.h>

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

描述

strsep() 函数在由 *stringp 引用的字符串中定位字符串 delim 中的任何字符的第一次出现(或终止字符 '\0' )并将其替换为 '\0'。分隔符字符之后的下一个字符的位置(或如果达到字符串的末尾,则为NULL)存储在 *stringp 中。返回 *stringp 的原始值。

可以通过比较返回指针引用的位置与 '\0' 来检测到“空”字段(即,字符串 delim 中的字符出现在 *stringp 的第一个字符位置)。

如果 *stringp 最初为 NULLstrsep() 返回 NULL

strtok() 相反,该函数不会在静态变量中存储上下文,因此它是线程安全的和可重入的,可以在嵌套循环中使用。在循环中使用时,由于所有调用具有相同的参数,因此更容易使用。

如果在您的平台上不可用该函数,您可以使用以下定义:

#include <string.h>

char *strsep(char **stringp, const char *delim) {
    char *start = *stringp;
    if (start) {
        /* 跳过标记中的所有字符(非分隔符) */
        char *p = start + strcspn(start, delim);
        if (*p) {
            *p++ = '
#include <string.h>

char *strsep(char **stringp, const char *delim) {
    char *start = *stringp;
    if (start) {
        /* 跳过标记中的所有字符(非分隔符) */
        char *p = start + strcspn(start, delim);
        if (*p) {
            *p++ = '\0';
            *stringp = p;
        } else {
            *stringp = NULL;
        }
    }
    return start;
}
'
;
*stringp = p; } else { *stringp = NULL; } } return start; }

以下是您的测试代码的修改版本:

#include <stdio.h>
#include <string.h>

int main(void) {
    char str[] = "a--b-c";
    const char *delim = "-";
    char *token;
    char *ctx = str;

    while ((token = strsep(&ctx, delim)) != NULL) {
        printf("element is: >>>%s<<<\n", token);
    }
    return 0;
}

输出:

element is: >>>a<<<
element is: >>><<<
element is: >>>b<<<
element is: >>>c<<<
英文:

strtok does not work the way you expect. The specification for this function is clear: all sequences of characters from the delimiter string form single delimiters and initial and trailing delimiters are consumed without producing tokens. Therefore strtok() never produces empty tokens.

The rationale for this is the original purpose of this function: to split words separated by whitespace. Passing a separator string of &quot; \t\f\r\n\v&quot; achieves this goal and it is rather intuitive that sequences of white space characters be considered a single separator.

The behavior you describe corresponds to the strsep() function originally developed for the BSD Unix variant and available on most Unix platforms, including linux. Here is an abstract from the manual page:

> NAME
>
> strsep - separate strings
>
>SYNOPSIS
>
> #include <string.h>
>
> char *strsep(char **stringp, const char *delim);
>
> DESCRIPTION
>
> The strsep() function locates, in the string referenced by *stringp, the first occurrence of any character in the string delim (or the terminating &#39;\0&#39; character) and replaces it with a &#39;\0&#39;. The location of the next character after the delimiter character (or NULL, if the end of the string was reached) is stored in *stringp. The original value of *stringp is returned.
>
> An "empty" field (i.e., a character in the string delim occurs as the first character of *stringp) can be detected by comparing the location referenced by the returned pointer to &#39;\0&#39;.
>
> If *stringp is initially NULL, strsep() returns NULL.

Contrary to strtok(), this function does not store a context in a static variable, so it is thread safe and reentrant, it can be used in nested loops. It is also easier to use in loops as all calls in the sequence have the same arguments.

If this function is not available on your platform, you can use this definition:

#include &lt;string.h&gt;

char *strsep(char **stringp, const char *delim) {
    char *start = *stringp;
    if (start) {
        /* skip all characters in the token (not delimiters) */
        char *p = start + strcspn(start, delim);
        if (*p) {
            *p++ = &#39;
#include &lt;string.h&gt;
char *strsep(char **stringp, const char *delim) {
char *start = *stringp;
if (start) {
/* skip all characters in the token (not delimiters) */
char *p = start + strcspn(start, delim);
if (*p) {
*p++ = &#39;\0&#39;;
*stringp = p;
} else {
*stringp = NULL;
}
}
return start;
}
&#39;; *stringp = p; } else { *stringp = NULL; } } return start; }

Here is a modified version of your test code:

#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

int main(void) {
    char str[] = &quot;a--b-c&quot;;
    const char *delim = &quot;-&quot;;
    char *token;
    char *ctx = str;

    while ((token = strsep(&amp;ctx, delim)) != NULL) {
        printf(&quot;element is: &gt;&gt;&gt;%s&lt;&lt;&lt;\n&quot;, token);
    }
    return 0;
}

Output:

element is: &gt;&gt;&gt;a&lt;&lt;&lt;
element is: &gt;&gt;&gt;&lt;&lt;&lt;
element is: &gt;&gt;&gt;b&lt;&lt;&lt;
element is: &gt;&gt;&gt;c&lt;&lt;&lt;

huangapple
  • 本文由 发表于 2023年6月8日 17:17:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430344.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定