这里介绍的函数主要有:strcat, strcmp, strcasecmp, strcpy, strdup, strlen, strchr, strrchr, strstr, strpbrk, strspn, strcspn, strtok. 在本章的最后还会给出这些库函数的具体实现,以应付一些企业的面试。
文章共分四个部分,第一部分直接列出了常用的字符串处理函数,由于这些都是大家平时接触的比较多的,在此不再多说;第二部分介绍了不太常用的字符串处理函数,并给出了具体示例,很多函数看名字很难猜到它的具体作用,但是一个小小的例子就能解释得很清楚;第三部分给出了这些函数的具体实现,大部分参考网上个人认为已经不错的实现,部分是查看glibc源代码后,简化得来的程序;第四部分作者非常道德的给出了参考资料。
常用的字符串处理函数:
char *strcat(char *s1, const char *s2);
size_t strlen(const char *s1);
不太常用的字符串处理函数:
//the strdup() function allocates memory and copies into it the string addressed s1. including the terminating null character.
//It is the use's responsibility to free the allocated storage by calling free()
char *strchr(const char *s1, int c);
char *strrchr(const char *s1, int c);