什么是用C strtok_r和strtok_s之间的区别? [英] What's the difference between strtok_r and strtok_s in C?

查看:3014
本文介绍了什么是用C strtok_r和strtok_s之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在这需要能够在Linux和Windows编译C程序来使用这个功能。起初,我尝试使用strtok_r,但后来当我在Windows上编译,它抱怨不存在功能,并表示将假设它是一个外部函数,但失败了。然后我用strtok_s并编译了!然后我试图在Linux上,但现在它的抱怨,有一个未定义的引用strtok_s'。

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'".

是一个仅适用于Windows功能和其他Linux的功能?我能做些什么,使其编译两个?

Is one a windows only function and the other a linux function??? What can I do to make it compile on both?

推荐答案

这两个功能对于解析字符串真难看,直观成语,通常无法满足微妙的方式您的特定应用的需求。即使moreso在标准C.平原 strtok的就扔出来,写自己的code遍历字符阵列,并根据需要打破它。 和strchr strspn strcspn 可以在做有益的这或者你可以从头开始工作阵列上。

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.

这篇关于什么是用C strtok_r和strtok_s之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆