I'm trying to use this function in a C program that needs to be able to compile in Linux and Windows. At first I tried using strtok_r, but then when I compiled on windows, it complained about the function not existing and said it would assume it's an extern function, but then failed. I then used strtok_s and it compiled! Then I tried on Linux but now it's complaining that there is an "undefined reference to 'strtok_s'".
Is one a windows only function and the other a linux function??? What can I do to make it compile on both?
Both of these functions are really ugly, unintuitive idioms for parsing strings, and usually fail to meet your particular application's requirements in subtle ways. Even moreso for the plain strtok
in standard C. Just throw them out and write your own code to iterate over the char
array and break it up as needed. strchr
, strspn
, and strcspn
can be helpful in doing this or you can just work from scratch on the array.