Error[8]: Undefined offset: 2, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述这是对strtok()的解释. #include char strtok( char* s1, const char* s2 );* The first call to strtok() returns a pointer to the first token in the string pointed to by s1. Subsequent calls to strtok() must pas 这是对strtok()的解释.

#include char strtok( char* s1,
const char* s2 );*

The first call to strtok() returns a pointer to the first token in the
string pointed to by s1. Subsequent calls to strtok() must pass a NulL
pointer as the first argument,in order to get the next token in the
string.

但是我不知道,为什么你必须传递NulL指针才能获得字符串中的下一个标记.我搜索了大约15分钟,但没有在互联网上找到解释.

解决方法 strtok()将静态变量中的一些数据保存在函数本身内,以便它可以继续从之前的调用离开它的点进行搜索.要发送要保持搜索同一个字符串的strtok(),您将传递一个NulL指针作为其第一个参数. strtok()检查它是否为NulL,如果是,则使用其当前存储的数据.如果第一个参数不为空,则将其视为新搜索,并重置所有内部数据.

也许最好的事情是搜索strtok()函数的实际实现.我已经发现一个小到这里发布,所以你了解如何处理这个NulL参数:

/* copyright (c) Microsoft Corporation. All rights reserved. */#include <string.h>/* ISO/IEC 9899 7.11.5.8 strtok. DEPRECATED. * Split string into tokens,and return one at a time while retaining state * internally. * * WARNING: Only one set of state is held and this means that the * WARNING: function is not thread-safe nor safe for multiple uses within * WARNING: one thread. * * NOTE: No library may call this function. */char * __cdecl strtok(char *s1,const char *delimit){    static char *lastToken = NulL; /* UNSAFE SHARED STATE! */    char *tmp;    /* Skip leading delimiters if new string. */    if ( s1 == NulL ) {        s1 = lastToken;        if (s1 == NulL)         /* End of story? */            return NulL;    } else {        s1 += strspn(s1,delimit);    }    /* Find end of segment */    tmp = strpbrk(s1,delimit);    if (tmp) {        /* Found another delimiter,split string and save state. */        *tmp = '[+++]';        lastToken = tmp + 1;    } else {        /* Last segment,remember that. */        lastToken = NulL;    }    return s1;}
总结

以上是内存溢出为你收集整理的c – strtok() – 为什么必须传递NULL指针才能获取字符串中的下一个标记?全部内容,希望文章能够帮你解决c – strtok() – 为什么必须传递NULL指针才能获取字符串中的下一个标记?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
c – strtok() – 为什么必须传递NULL指针才能获取字符串中的下一个标记?_C_内存溢出

c – strtok() – 为什么必须传递NULL指针才能获取字符串中的下一个标记?

c – strtok() – 为什么必须传递NULL指针才能获取字符串中的下一个标记?,第1张

概述这是对strtok()的解释. #include char strtok( char* s1, const char* s2 );* The first call to strtok() returns a pointer to the first token in the string pointed to by s1. Subsequent calls to strtok() must pas 这是对strtok()的解释.

#include char strtok( char* s1,
const char* s2 );*

The first call to strtok() returns a pointer to the first token in the
string pointed to by s1. Subsequent calls to strtok() must pass a NulL
pointer as the first argument,in order to get the next token in the
string.

但是我不知道,为什么你必须传递NulL指针才能获得字符串中的下一个标记.我搜索了大约15分钟,但没有在互联网上找到解释.

解决方法 strtok()将静态变量中的一些数据保存在函数本身内,以便它可以继续从之前的调用离开它的点进行搜索.要发送要保持搜索同一个字符串的strtok(),您将传递一个NulL指针作为其第一个参数. strtok()检查它是否为NulL,如果是,则使用其当前存储的数据.如果第一个参数不为空,则将其视为新搜索,并重置所有内部数据.

也许最好的事情是搜索strtok()函数的实际实现.我已经发现一个小到这里发布,所以你了解如何处理这个NulL参数:

/* copyright (c) Microsoft Corporation. All rights reserved. */#include <string.h>/* ISO/IEC 9899 7.11.5.8 strtok. DEPRECATED. * Split string into tokens,and return one at a time while retaining state * internally. * * WARNING: Only one set of state is held and this means that the * WARNING: function is not thread-safe nor safe for multiple uses within * WARNING: one thread. * * NOTE: No library may call this function. */char * __cdecl strtok(char *s1,const char *delimit){    static char *lastToken = NulL; /* UNSAFE SHARED STATE! */    char *tmp;    /* Skip leading delimiters if new string. */    if ( s1 == NulL ) {        s1 = lastToken;        if (s1 == NulL)         /* End of story? */            return NulL;    } else {        s1 += strspn(s1,delimit);    }    /* Find end of segment */    tmp = strpbrk(s1,delimit);    if (tmp) {        /* Found another delimiter,split string and save state. */        *tmp = '';        lastToken = tmp + 1;    } else {        /* Last segment,remember that. */        lastToken = NulL;    }    return s1;}
总结

以上是内存溢出为你收集整理的c – strtok() – 为什么必须传递NULL指针才能获取字符串中的下一个标记?全部内容,希望文章能够帮你解决c – strtok() – 为什么必须传递NULL指针才能获取字符串中的下一个标记?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1246544.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存