# ctoolkit **Repository Path**: cwl2914/ctoolkit ## Basic Information - **Project Name**: ctoolkit - **Description**: C语言常用工具函数库 - 包含字符串、数组、内存、数学、文件和链表操作 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-28 - **Last Updated**: 2026-02-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # C Toolkit 一个包含常用C语言工具函数的项目,提供字符串处理、数组操作、内存管理、数学运算等功能。 ## 项目结构 ``` c-toolkit/ ├── include/ # 头文件 │ └── toolkit.h # 主要头文件 ├── src/ # 源代码 │ └── toolkit.c # 函数实现 ├── tests/ # 测试用例 │ └── test_toolkit.c ├── examples/ # 使用示例 │ └── example.c ├── docs/ # 文档 ├── Makefile # 构建文件 └── README.md # 项目说明 ``` ## 功能模块 ### 1. 字符串处理 - `str_reverse()` - 字符串反转 - `str_find()` - 查找子串 - `str_to_int()` - 字符串转整数 ### 2. 数组操作 - `array_sum()` - 数组求和 - `array_max()` - 查找最大值 - `array_min()` - 查找最小值 - `array_bubble_sort()` - 冒泡排序 ### 3. 内存操作 - `memory_copy()` - 内存拷贝(支持重叠) - `memory_set()` - 内存设置 ### 4. 数学运算 - `is_prime()` - 素数判断 - `factorial()` - 阶乘计算 ### 5. 文件操作 - `file_read()` - 读取文件内容 - `file_write()` - 写入文件内容 ### 6. 链表操作 - `list_create()` - 创建链表节点 - `list_append()` - 追加节点 - `list_free()` - 释放链表 ## 构建和使用 ### 使用GCC编译 ```bash # 编译库 gcc -c src/toolkit.c -Iinclude -o toolkit.o ar rcs libtoolkit.a toolkit.o # 编译测试程序 gcc tests/test_toolkit.c toolkit.o -Iinclude -o test_toolkit # 编译示例程序 gcc examples/example.c toolkit.o -Iinclude -o example ``` ### 使用Makefile ```bash # 构建所有目标 make all # 运行测试 make test # 运行示例程序 make run_example # 清理构建文件 make clean ``` ## 快速开始 ```c #include "toolkit.h" #include int main() { // 使用字符串反转 char str[] = "Hello"; str_reverse(str); printf("%s\n", str); // 输出: olleH // 使用数组操作 int numbers[] = {3, 1, 4, 1, 5}; printf("总和: %d\n", array_sum(numbers, 5)); printf("最大值: %d\n", array_max(numbers, 5)); // 使用数学函数 printf("5! = %llu\n", factorial(5)); printf("7是素数吗? %s\n", is_prime(7) ? "是" : "不是"); return 0; } ``` ## 运行测试 项目包含完整的测试用例,确保所有函数正常工作: ```bash # 运行测试套件 make test # 或者直接运行测试程序 ./toolkit_test ``` ## API文档 ### 字符串函数 ```c // 反转字符串 char* str_reverse(char* str); // 查找子串 char* str_find(const char* haystack, const char* needle); // 字符串转整数 int str_to_int(const char* str); ``` ### 数组函数 ```c // 数组求和 int array_sum(int* arr, size_t size); // 查找最大值 int array_max(int* arr, size_t size); // 查找最小值 int array_min(int* arr, size_t size); // 冒泡排序 void array_bubble_sort(int* arr, size_t size); ``` ### 内存函数 ```c // 内存拷贝(支持重叠) void* memory_copy(void* dest, const void* src, size_t n); // 内存设置 void* memory_set(void* s, int c, size_t n); ``` ### 数学函数 ```c // 判断素数 bool is_prime(int n); // 计算阶乘 unsigned long long factorial(int n); ``` ### 文件函数 ```c // 读取文件内容 char* file_read(const char* filename); // 写入文件内容 bool file_write(const char* filename, const char* content); ``` ### 链表函数 ```c // 链表节点结构 typedef struct ListNode { int data; struct ListNode* next; } ListNode; // 创建节点 ListNode* list_create(int data); // 追加节点 void list_append(ListNode** head, int data); // 释放链表 void list_free(ListNode* head); ``` ## 许可证 本项目采用MIT许可证。详见LICENSE文件。 ## 贡献指南 欢迎提交Issue和Pull Request! 1. Fork本仓库 2. 创建功能分支 (`git checkout -b feature/amazing-feature`) 3. 提交更改 (`git commit -m 'Add some amazing feature'`) 4. 推送到分支 (`git push origin feature/amazing-feature`) 5. 创建Pull Request ## 致谢 感谢所有为C语言社区做出贡献的开发者们!