c++ 函数,strtok() cplusplus.com
如果str未正确终止,此示例是否会遭受缓冲区溢出?
/* strtok example */
/* source - cplusplus.com (see link below) */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-"); // walk the stack?
}
return 0;
}
如果str没有以“\0”正确终止,是不是可以
pch = strtok (NULL, " ,.-");
走堆栈?
谢谢!