Implemented strcspn

This commit is contained in:
2022-02-04 15:08:10 +00:00
parent 15091303fc
commit 8de49a1491
2 changed files with 16 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ extern char *strcpy(char *dest, const char *src);
extern char *strncpy(char *dest, const char *src, size_t sz);
extern char *strrchr(const char *s, int c);
extern size_t strcspn(const char *str1, const char *str2);
extern char *strdup(const char *s);

View File

@@ -0,0 +1,15 @@
#include <stddef.h>
size_t strcspn(const char *str1, const char *str2)
{
size_t i;
for (i = 0; str1[i]; i++) {
for (size_t ii = 0; str2[ii]; ii++) {
if (str1[i] == str2[ii]) {
return i;
}
}
}
return i;
}