Files
magnitudelib/include/string.h

52 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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