// // Created by dongl on 25-7-30. // #ifndef LIBK_STRING_H #define LIBK_STRING_H #include "stddef.h" // for size_t #ifdef __cplusplus extern "C" { #endif // 计算字符串长度(不包含结尾的 '\0') size_t strlen(const char *str); // 复制字符串 src 到 dest,返回 dest char *strcpy(char *dest, const char *src); // 最多复制 n 个字符到 dest(不足补零),返回 dest char *strncpy(char *dest, const char *src, size_t n); // 比较两个字符串,相等返回 0 int strcmp(const char *s1, const char *s2); // 比较两个字符串,最多比较 n 个字符 int strncmp(const char *s1, const char *s2, size_t n); // 查找字符 c 在字符串中第一次出现的位置 char *strchr(const char *s, int c); // 查找字符 c 在字符串中最后一次出现的位置 char *strrchr(const char *s, int c); // 拼接 src 到 dest 的末尾,返回 dest char *strcat(char *dest, const char *src); // 最多拼接 n 个字符 char *strncat(char *dest, const char *src, size_t n); // 查找子串 needle 在 haystack 中第一次出现的位置 char *strstr(const char *haystack, const char *needle); // 可选:复制字符串(需要分配内存) char *strdup(const char *s); // 如果你实现了 malloc() #ifdef __cplusplus } #endif #endif // LIBK_STRING_H