企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
但查看提交详细资料后,Byron 实现字符串的长度不能为负数,所以他决定改变my_strlen函数的返回类型。 Byron 使用git日志命令来查看日志信息。 [byron@CentOS project]$ git log 上面的命令会产生以下结果。 commit cbe1249b140dad24b2c35b15cc7e26a6f02d2277 Author: Byron <xiaobosun@gridinfo.com.cn> Date: Wed Sep 11 08:05:26 2015 +0530 Implemented my_strlen function Byron 使用git show命令查看提交的细节。 Git的show命令的SHA-1提交ID作为参数。 [byron@CentOS project]$ git show cbe1249b140dad24b2c35b15cc7e26a6f02d2277 上面的命令会产生以下结果。 commit cbe1249b140dad24b2c35b15cc7e26a6f02d2277 Author: Byron <xiaobosun@gridinfo.com.cn> Date: Wed Sep 11 08:05:26 2015 +0530 Implemented my_strlen function diff --git a/string.c b/string.c new file mode 100644 index 0000000..187afb9 --- /dev/null +++ b/string.c @@ -0,0 +1,24 @@ +#include <stdio.h> + +int my_strlen(char *s) +{ + char *p = s; + + while (*p) + ++p; + return (p -s ); +} + 他改变了函数的返回类型 从int 修改为 size_t。测试代码后,他查看其变化运行git diff命令。 [byron@CentOS project]$ git diff 上面的命令会产生以下结果。 diff --git a/string.c b/string.c index 187afb9..7da2992 100644 --- a/string.c +++ b/string.c @@ -1,6 +1,6 @@ #include <stdio.h> -int my_strlen(char *s) +size_t my_strlen(char *s) { char *p = s; @@ -18,7 +18,7 @@ int main(void) }; for (i = 0; i < 2; ++i) - printf("string lenght of %s = %d ", s[i], my_strlen(s[i])); + printf("string lenght of %s = %lu ", s[i], my_strlen(s[i])); return 0; } Git 的差异显示+号前行,这是新增加的,并显示符号被删除。