Skip to content

Commit

Permalink
Fixed some errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-n3m0 committed May 11, 2023
1 parent 261ef58 commit 2299308
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions string/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,19 @@ int tonumericdigit(char c)

return c - '0';
}
void *memset(void *s, int c, size_t n) {
unsigned char *p = s;
while (n--) {
*p++ = (unsigned char)c;
}
return s;
}

int memcmp(const void *s1, const void *s2, size_t n) {
const unsigned char *p1 = s1, *p2 = s2;
while (n-- && (*p1 == *p2)) {
p1++;
p2++;
}
return (n < 0) ? 0 : (*p1 - *p2);
}
2 changes: 2 additions & 0 deletions string/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ int isdigit(char c);
*/
int tonumericdigit(char c);

void *memset(void *s, int c, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);
#endif

0 comments on commit 2299308

Please sign in to comment.