【文件属性】:
文件名称:strtok的缺陷,使用strtok_s函数更新安全度
文件大小:8.26MB
文件格式:RAR
更新时间:2021-05-02 10:55:42
c代码
strtok的缺陷,使用strtok_s函数更新安全度
#include "stdafx.h"
#include "Windows.h"
#include
#include
using namespace std;
char string1[] = "A string\tof ,,tokens\nand some more tokens";
char string2[] = "Another string\n\tparsed at the same time.";
char separators[] = " ,\t\n";
char *token1, *token2, *next_token1, *next_token2;
int main(void)
{
cout << "Tokens:" << endl;
// establish a string and get the first token:
token1 = strtok_s(string1, separators, &next;_token1);
token2 = strtok_s(string2, separators, &next;_token2);
// while there are tokens in "string1" or "string2"
while ((token1 != NULL))
{
// get the next token:
if (token1 != NULL)
{
cout << token1 << endl;
token1 = strtok_s(NULL, separators, &next;_token1);
OutputDebugString(_T(token1));
}
}
while ((token2 != NULL))
{
// get the next token:
if (token2 != NULL)
{
cout << token2 << endl;
token2 = strtok_s(NULL, separators, &next;_token2);
OutputDebugString(_T(token2));
}
}
Sleep(3000);
system("pause");
【文件预览】:
app01
----说明.txt(1KB)
----ipch()
--------APP01-ad89d813()
----.vs()
--------app01()
----Debug()
--------app01.pdb(1.04MB)
--------app01.exe(46KB)
--------app01.ilk(355KB)
----app01()
--------ReadMe.txt(1KB)
--------stdafx.h(234B)
--------Debug()
--------stdafx.cpp(209B)
--------targetver.h(240B)
--------app01.vcxproj.filters(1KB)
--------app01.vcxproj(8KB)
--------app01.cpp(2KB)
----app01.VC.db(28.19MB)
----app01.sln(1KB)