• 归纳整理Linux下C语言常用的库函数----内存及字符串控制及操作


    在没有IDE的时候,记住一些常用的库函数的函数名、参数、基本用法及注意事项是很有必要的。

    参照Linux_C_HS.chm的目录,我大致将常用的函数分为一下几类:

    • 1. 内存及字符串控制及操作
    • 2. 字符串转换
    • 3. 字符测试
    • 4. 文件操作
    • 5. 时间日期
    • 6. 常用数学函数
    • 7. 文件内容操作
    • 8. 文件权限控制
    • 9. 进程操作
    • 10. 线程操作
    • 11. Socket操作
    • 12. 信号处理
    • 13. 数据结构及算法

    以下是对第一项 内存及字符串控制及操作 的归纳整理。

    • 已经不赞成使用的函数归类
    *
    *           函数名                                                   用途                                    替换方案
    *1. int bcmp(const void *s1, const void *s2, size_t n);         compare byte sequences                        memcmp
    *
    *2. void bcopy(const void *src, void *dest, size_t n);          copy byte sequence                            memcpy Or memmove
    *
    *3. void bzero(void *s, size_t n);                              write zero-valued bytes                       memset
    *
    *4. char *index(const char *s, int c);                          locate character in string                    strchr
    *
    *5. char *rindex(const char *s, int c);                         locate character in string                    strrchr
    *
    • 内存或字符串查找函数归类
    *           函数名                                                   用途                                       备注
    *1. void *memchr(const void *s, int c, size_t n);       scan memory for a character (Forward)       return a pointer to the matching byte or NULL if the
                                                                                                         character does not occur  in  the  given  memory area.
    *
    *2. void *memrchr(const void *s, int c, size_t n);      scan memory for a character  (Backward)      return a pointer to the matching byte or NULL if the
                                                                                                         character does not occur  in  the  given  memory area.
    *
    *3. char *strchr(const char *s, int c);                 locate character in string  (Forward)        return a pointer to the matched character or NULL if
                                                                                                         the character is not found.
    *
    *4. char *strrchr(const char *s, int c);                locate character in string  (Backward)       return a pointer to the matched character or NULL if
                                                                                                         the character is not found.
    *
    *5. char *strstr(const char *haystack, const char *needle);       locate a substring                 return a pointer to the beginning of the substring,
                                                                                                         or NULL if the substring is not found.
    *
    *6. char *strcasestr(const char *haystack, const char *needle);   locate a substring,ignores the     return a pointer to the beginning of the substring,
                                                                      case of both arguments.            or NULL if the substring is not found.
    *
    • 内存及字符串拷贝、比较函数归类
    *           函数名                                                  用途                                        备注
    *
    *1. void *memcpy(void *dest, const void *src, size_t n);        copy memory area                      The memcpy() function returns a pointer to dest.
    *
    *2. char *strcpy(char *dest, const char *src);                  copy a string                         return a pointer to the destination string dest.
    *
    *3. char *strncpy(char *dest, const char *src, size_t n);       copy a string                         return a pointer to the destination string dest.
    *
    *4. void *memmove(void *dest, const void *src, size_t n);       copy memory area , may overlap        returns a pointer to dest.
    *
    *5. int memcmp(const void *s1, const void *s2, size_t n);       compare memory areas                  returns an integer less than, equal to, or greater than zero if the first n bytes of s1 is found
    *
    *6. int strcmp(const char *s1, const char *s2);                 compare two strings                   return an integer less than, equal to, or greater than zero if s1 is foundfound
    *
    *7. int strncmp(const char *s1, const char *s2, size_t n);      compare two strings                   UP
    *
    *8. int strcasecmp(const char *s1, const char *s2);             compare two strings ignoring case     UP
    *
    *9. int strncasecmp(const char *s1, const char *s2, size_t n);  compare two strings ignoring case     UP
    *
    * 10. char *strdup(const char *s);                              duplicate a string                     returns a pointer to a new string which is a duplicate of the string s.  Memory for the new string is obtained with
    * 
    • 内存或字符串连接、分割、求长等函数归类
    *           函数名                                                  用途                                            备注
    *1. char *strcat(char *dest, const char *src);                  concatenate two strings                 return a pointer to the resulting string dest
    *
    *2. char *strncat(char *dest, const char *src, size_t n);       UP                                      UP
    *
    *3. char *strtok(char *str, const char *delim);                 extract tokens from strings             第一次调用时,str必须不为空,第二次调用str必须为空
    *
    *4. char *strtok_r(char *str, const char *delim, char **saveptr);   可重入函数,线程安全                推荐使用这个分割函数,具体讨论见http://blog.csdn.net/liuintermilan/article/details/6283705
    *

    以上,就是对第一项的整理归纳。接下来,会对第二项 字符串转换  进行归纳。

  • 相关阅读:
    pytest之断言
    python之self
    python标准数据结构类型
    pytest之fixture
    python之继承和多态
    安卓UI自动化,pytest+UIautomator2+allure+jenkins
    airtest
    Python中单下划线开头的特性
    系统默认分配的共享内存太小,导致zabbix_server无法启动
    运行yum报错Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
  • 原文地址:https://www.cnblogs.com/xiaowenhu/p/4076791.html
Copyright © 2020-2023  润新知