1
0
Fork 0

strchr(3), strchrnul(3), strrchr(3)

This commit is contained in:
dtb 2022-10-20 22:19:18 -04:00
parent 60d384a298
commit 87b515fa20
2 changed files with 41 additions and 2 deletions

View File

@ -1,3 +1,39 @@
char *
strchr(const char *s, int c){
char *r;
for(r = s; ; ++r){
if(*r == c)
return r;
if(*r == '\0')
return NULL;
}
}
char *
strrchr(const char *s, int c){
char *r;
char *p;
for(p = s, r = NULL; ; ++p){
if(*p == c)
r = p;
if(*p == '\0')
break;
}
return r;
}
char *
strchrnul(const char *s, int c){
char *r;
for(r = s; ; ++r)
if(*r == c || r == '\0')
return r;
}
size_t
strlen(const char *s){
size_t r;

View File

@ -1,5 +1,8 @@
#ifndef _STRING_H
# define _STRING_H
size_t strlen(const char *s);
size_t strnlen(const char *s, size_t maxlen);
char * strchr(const char *s, int c);
char * strrchr(const char *s, int c);
char *strchrnul(const char *s, int c);
size_t strlen(const char *s);
size_t strnlen(const char *s, size_t maxlen);
#endif /* ifndef _STRING_H */