Home > Back-end >  Under strtok_s () function in c and c compiler
Under strtok_s () function in c and c compiler

Time:10-30

Following this code, put in a. C file, Windows with GCC compiler can pass, but on a. CPP file under Windows with g + + compiler error: error: 'strtok_s' was not declared in this scope
 # include & lt; String. H> 
#include

Char string []=". A string \ tof,, tokens \ nand some more tokens ".
Char seps []=", \ t \ n ";
Char * token=NULL;
Char * next_token=NULL;

Int main (void)
{
Printf (" Tokens: \ n ");

//Establish string and get the first token:
Token=strtok_s (string, seps, & amp; Next_token);

//While there are tokens in "string1" or "string2"
While (token!=NULL)
{
//Get the next token:
If (token!=NULL)
{
Printf (" % s \ n ", token);
Token=strtok_s (NULL, seps, & amp; Next_token);
}
}
Printf (" the rest token1: \ n ");
Printf (" % d ", token);
}

Why is this excuse me?

CodePudding user response:

Char * strtok_s (char *, restrict the STR, rsize_t * restrict strmax,
Const char * restrict delim, char * * restrict PTR); (2) ( since C11 )

CodePudding user response:

Try the strtok_r, this should be in c and c + + can be ~
  • Related