Show HN:我重写了一些常用的 string.h 函数
Show HN: I rewrote few of the common core string.h functions

原始链接: https://github.com/deep-vinci/re-implement-c

1. strlen() 返回字符串中字符的个数,不包括空终止符 \0。 2. strcpy() 将 src 字符串的内容复制到 dest。 3. strcat() 将 src 字符串追加到 dest 的末尾。 4. strncat() 将 src 中最多 n 个字符追加到 dest。 5. strcmp() 比较两个字符串,如果相等则返回 0。 6. strcspn() 在字符串数组中查找字符。 7. strerror() 返回错误代码的字符串描述。 8. memchr() 返回指向内存块中第一个包含指定值的字节的指针。 9. strrev() 返回字符串的反转(非官方)。

Deepvinci在Hacker News上分享了他们用C语言重新实现常用string.h函数的代码,主要目的是学习练习,以提高对指针和字符串的理解。帖子发布后立即收到了反馈。Gthompson512建议研究musl libc中更复杂的实现,以了解健壮、可用于生产环境的代码所需的细微之处和优化。TheSoftwareGuy询问这个项目是用于实际应用还是纯粹的教育目的。帖子最后还号召大家加入AI创业学校。
相关文章
  • (评论) 2025-03-20
  • C++ 中愚蠢的智能指针 2025-03-17
  • (评论) 2025-03-19
  • (评论) 2025-03-25
  • (评论) 2025-03-17

  • 原文
    1 strlen() Returns the number of characters in the string, excluding the null terminator \0. 2 strcpy() Copies contents of src string to dest. 3 strcat() Appends src string to the end of dest. 4 strncat() Appends up to n characters from src to dest. 5 strcmp() Compares two strings and returns 0 if equal. 6 strcspn() Finds a character from a array of string 7 strerror() Returns the string description of an error code. 8 memchr() Returns a pointer to the first byte in a block of memory which contains a specified value 9 strrev() Returns the reverse of the string (unofficial)
    联系我们 contact @ memedata.com