add strstr
This commit is contained in:
parent
f3f9756106
commit
9de9eacb1d
@ -11,6 +11,8 @@ char* strncpy(char* dest, const char* src, size_t n);
|
|||||||
int strncmp(const char* s1, const char* s2, size_t n);
|
int strncmp(const char* s1, const char* s2, size_t n);
|
||||||
char* strncat(char* dest, const char* src, size_t n);
|
char* strncat(char* dest, const char* src, size_t n);
|
||||||
|
|
||||||
|
char* strstr(char* haystack, char* needle);
|
||||||
|
|
||||||
void* memcpy(void* dest, const void* src, size_t n);
|
void* memcpy(void* dest, const void* src, size_t n);
|
||||||
void* memset(void* dest, int c, size_t n);
|
void* memset(void* dest, int c, size_t n);
|
||||||
int memcmp(const void* a, const void* b, size_t n);
|
int memcmp(const void* a, const void* b, size_t n);
|
||||||
|
@ -66,6 +66,26 @@ char* strcat(char* dest, const char* src)
|
|||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* strstr(char* haystack, char* needle)
|
||||||
|
{
|
||||||
|
size_t needle_size = strlen(needle);
|
||||||
|
size_t haystack_size = strlen(haystack);
|
||||||
|
while (*haystack)
|
||||||
|
{
|
||||||
|
if (*haystack == *needle)
|
||||||
|
{
|
||||||
|
if (needle_size <= haystack_size)
|
||||||
|
{
|
||||||
|
if (!strncmp(haystack, needle, needle_size)) return haystack;
|
||||||
|
}
|
||||||
|
else { return NULL; }
|
||||||
|
}
|
||||||
|
haystack++;
|
||||||
|
haystack_size--;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void* memcpy(void* dest, const void* src, size_t n)
|
void* memcpy(void* dest, const void* src, size_t n)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < n; ++i) { *((char*)dest + i) = *((char*)src + i); }
|
for (size_t i = 0; i < n; ++i) { *((char*)dest + i) = *((char*)src + i); }
|
||||||
|
Loading…
Reference in New Issue
Block a user