commit 6a837b5cd9698db9a446928e665cc62d7ca68994
parent 8e72d1ebba101811cbea4da918f2f9912749a250
Author: evenfri <evenfri256@gmail.com>
Date: Sun, 9 Aug 2026 01:43:18 +0800
update strchr
Diffstat:
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/libc.h b/libc.h
@@ -102,7 +102,7 @@ void* realloc(void *ptr, size_t size);
/* string functions */
size_t strlen(const char *str);
-char *strchr(const char *str, int c);
+char *strchr(const char *s, int c);
int strcmp(const char *s1, const char *s2);
char* strtok(char *str, const char *delim);
diff --git a/strchr.c b/strchr.c
@@ -4,13 +4,14 @@
*/
#include "libc.h"
-char *strchr(const char *str, int c) {
+
+char *strchr(const char *s, int c) {
char chr = (char)c;
int i = 0;
- while (str[i] != 0) {
- if (str[i] == chr)
- return (char*)str + i;
+ while (s[i] != 0) {
+ if (s[i] == chr)
+ return (char*)s + i;
i++;
}