1

I am using Visual Studio 2015, and I am trying to use strtok_r. For some reason the compiler is not recognizing it.

Here is my code:

#include <string.h>
#include <stdlib.h>
#include <assert.h>

char** str_split(char* a_str, const char a_delim, int * argc)
{
   ... some other code
   if (result)
    {
    size_t idx = 0;
    char* saveptr = a_str;
    char* token = strtok_r(a_str, delim, &saveptr);
    //char * token;
    while (token)
    {
        assert(idx < count);
        *(result + idx++) = strdup(token);
        token = strtok_r(0, delim, &saveptr);
    }
    assert(idx == count - 1);
    *(result + idx) = 0;
  }

return result;

I have been following this documentation: http://linux.die.net/man/3/strtok_r

Is the function deprecated? or am I making a silly mistake? Thank you in advance guys.

2
  • 3
    MS is not fully posix compliant. You need to read the MS documentation rather than the Linux documentation if you are programming with MS tools.
    – kaylum
    Commented Sep 15, 2016 at 0:24
  • 1
    For practical purposes, strtok_r() on POSIX-ish systems is equivalent to strtok_s() on Windows systems. That equivalence does not always work, but in this specific case, it does. Commented Sep 15, 2016 at 1:59

1 Answer 1

8

The Linux Man Pages don't provide documentation for Windows platforms. You'll need to use one of the following functions:

strtok_s, _strtok_s_l, wcstok_s, _wcstok_s_l, _mbstok_s, _mbstok_s_l

[0] https://msdn.microsoft.com/en-us/library/2c8d19sb.aspx

5
  • Certainly the issue is the compiler visual-studio-2015 and not the OS. Commented Sep 15, 2016 at 1:30
  • 1
    Visual Studio is only on the WIndows platform, so I thought it was implied
    – Ryan
    Commented Sep 15, 2016 at 1:48
  • @chux You are confusing the compiler and the standard library. strtok is a part of the standard library, not the compiler. It would be more correct in this case to say C implementation, which would cover both the compiler, the runtime and the standard library.
    – jforberg
    Commented Sep 15, 2016 at 2:02
  • @jforberg Agree comparing the C implementation is closer to the mark. My comment should have been directed to clarify "Linux Man Pages don't provide documentation for Windows platforms" is better stated as "Linux Man Pages don't provide documentation for visual-studio". Commented Sep 15, 2016 at 4:07
  • @chux nit: I know what you mean, but Visual Studio is an IDE, and without context it doesn't have to relate to C at all, so that's why I particularly used a broad statement that would include MSFT's C implementation (because the Windows platform has a C implementation)
    – Ryan
    Commented Sep 15, 2016 at 5:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.