strtok_s debugging problem

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a piece of code which has been complied by Dev C++ correctly. When I tried to execute it using VS2012 express I faced this warning warning C4996: : This function or variable may be unsafe. Consider using strtok_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details
I tried to disable security warnings, but I found _CRT_SECURE_NO_WARNINGS option is not available in my VS express. so I had to modify my code to use strtok_s instead of strtok to avoid this warning. However, even the code executes to the end without any errors, something went wrong that the results do not appear. obviously no reading files occur. This is the previous code which worked well on Dev C++const char* token[MAX_TOKENS_PER_LINE] = {}; // initialize to 0
// parse the line
token[0] = strtok(buf, DELIMITER); // first token
if (token[0]) // zero if line is blank
{
for (n = 1; n < MAX_TOKENS_PER_LINE; n++)
{
token[n] = strtok(0, DELIMITER); // subsequent tokens
if (!token[n]) break; // no more tokens

and this is what I tried to execute using VS2012 expressconst char* token[MAX_TOKENS_PER_LINE] = {}; // initialize to 0
char* next_token[MAX_TOKENS_PER_LINE] = {}; // initialize to 0
//char* next_token;
// parse the line
token[0] = strtok_s(buf, DELIMITER, &next_token[0]); // first token
if (token[0]) // zero if line is blank
{
for (n = 1; n < MAX_TOKENS_PER_LINE; n++)
{
token[n] = strtok_s(0, DELIMITER, &next_token[n]); // subsequent tokens
if (!token[n]) break; // no more tokens
What is wrong with the second code?

View the full article
 
Back
Top