C语言 <string.h> 和 <strings.h> 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4291149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 07:13:07  来源:igfitidea点击:

Difference between <string.h> and <strings.h>

cstringheader

提问by icktoofay

I noticed that there was (at least on Mac OS X) both a <string.h>header and a <strings.h>header. man 3 stringreveals that they contain different functions. Is there any reason for this?

我注意到(至少在 Mac OS X 上)有一个<string.h>标题和一个<strings.h>标题。man 3 string揭示它们包含不同的功能。这有什么原因吗?

回答by AProgrammer

strings.h comes from the BSD branch in the unix evolution. Its content has been standardized by POSIX, but most of it is marked as legacy and can be easily replaced with other functions:

strings.h 来自 unix 演进中的 BSD 分支。它的内容已经被 POSIX 标准化了,但是大部分都被标记为 legacy 并且可以很容易地替换为其他功能:

int    bcmp(const void *, const void *, size_t); /* LEGACY, see memcmp */
void   bcopy(const void *, void *, size_t); /* LEGACY, see memcpy, memmove */
void   bzero(void *, size_t); /* LEGACY, see memset */
int    ffs(int);
char  *index(const char *, int); /* LEGACY, see strchr */
char  *rindex(const char *, int); /* LEGACY, see strrchr */
int    strcasecmp(const char *, const char *);
int    strncasecmp(const char *, const char *, size_t);

回答by Paul R

Typically <strings.h>just adds some useful but non-standard additional string functions to the standard header <string.h>. For maximum portability you should only use <string.h>but if you need the functions in <strings.h>more than you need portability then you can use <strings.h>instead of <string.h>.

通常<strings.h>只是在标准 header 中添加一些有用但非标准的附加字符串函数<string.h>。为了获得最大的可移植性,你应该只使用<string.h>,但如果你需要的功能<strings.h>比你更需要的便携性,那么你可以使用<strings.h>的替代<string.h>