Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char *strstr(const char *haystack, const char *needle)
- {
- char *h;
- size_t needle_len;
- size_t i;
- size_t j;
- h = (char *)haystack;
- if (!(needle_len = strlen(needle)))
- return (h);
- i = 0;
- while (h[i])
- {
- j = 0;
- while (needle[j] && needle[j] == h[i + j])
- j++;
- if (j == needle_len)
- return (&h[i]);
- i++;
- }
- return (NULL);
- }
- int strncmp(const char *s1, const char *s2, size_t n)
- {
- if (!n)
- return (0);
- while (*s1 == *s2 && *s1 && --n)
- {
- s1++;
- s2++;
- }
- return ((int)((unsigned char)*s1 - (unsigned char)*s2));
- }
- char *strncat(char *restrict s1, const char *restrict s2, size_t n)
- {
- size_t i;
- size_t len;
- i = 0;
- len = strlen(s1);
- while (s2[i] && i < n)
- {
- s1[len + i] = s2[i];
- i++;
- }
- s1[len + i] = '\0';
- return (s1);
- }
- char *strchr(const char *s, int c)
- {
- while (*s)
- {
- if (*s == (char)c)
- return ((char *)s);
- s++;
- }
- if (!*s && c == '\0')
- return ((char *)s);
- return (NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement