string.c
569 Bytes
/* string functions */
#include <string.h>
char *strchr(const char *s, int c)
{ /* find first occurrence of c in char s[] */
const char ch = c;
for (; *s != ch; ++s)
if (*s == '\0')
return (NULL);
return ((char *) s);
}
size_t strlen(const char *s)
{ /* find length of s[] */
const char *sc;
for (sc = s; *sc != '\0'; ++sc);
return (sc - s);
}
void *memcpy(void *s1, const void *s2, size_t n)
{ /* copy char s2[n] to s1[n] in any order */
char *su1;
const char *su2;
for (su1 = s1, su2 = s2; 0 < n; ++su1, ++su2, --n)
*su1 = *su2;
return (s1);
}