What's the difference between strtok_r and strtok_s in C?

前端 未结 6 1152
刺人心
刺人心 2020-12-15 04:45

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,

6条回答
  •  春和景丽
    2020-12-15 05:31

    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.

提交回复
热议问题