-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standard library #11
Standard library #11
Conversation
include/ctype.h
Outdated
@@ -1,5 +1,5 @@ | |||
#ifndef _CTYPE_H | |||
# define _CTYPE_H 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format seems to donot take care of
IndentPPDirectives: AfterHash
PPIndentWidth: 1
This change must be reverted
include/math.h
Outdated
@@ -0,0 +1,11 @@ | |||
#ifndef _MATH_H | |||
#define _MATH_H 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a space must be added between #
and define
include/stddef.h
Outdated
@@ -0,0 +1,8 @@ | |||
#ifndef _STDDEF_H | |||
#define _STDDEF_H 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a space must be added between #
and define
include/stddef.h
Outdated
#ifndef _STDDEF_H | ||
#define _STDDEF_H 1 | ||
|
||
#define NULL ((void *)0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a space must be added between #
and define
src/string/cmp.c
Outdated
size_t len = strlen(s1); | ||
if (len > strlen(s2)) | ||
{ | ||
len = strlen(s2); | ||
} | ||
return (strncmp(s1, s2, len)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like I said on discord, I think it's wrong to use strlen and strncmp here
src/string/memset.c
Outdated
char *cs = (char *)s; | ||
unsigned char cc = (unsigned char)c; | ||
size_t i = 0; | ||
for (; i < n; i++) | ||
{ | ||
cs[i] = cc; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a blank line is needed between declaration and the rest of the program (here between line 8-9) also function must return a void *
also i
is not needed here, the function can be simplified:
void *
memset(void *s, int c, size_t n)
{
unsigned char *cs ;
cs =(unsigned char *)s;
while (i--)
{
cs++ = (unsigned char)c;
}
return (s);
}
src/string/strlen.c
Outdated
size_t | ||
strlen(const char *s) | ||
{ | ||
size_t i = 0; | ||
while (s[i++] != 0) | ||
; | ||
return (i - 1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size_t i;
i = 0;
while(*s != '\0')
{
i++;
s++;
}
return (i);
src/string/memmove.c
Outdated
|
||
cs1 = (char *)s1; | ||
cs2 = (const char *)s2; | ||
if (cs2 + n >= cs1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be cs1 > cs2
also the case where cs1 == cs2 should be added (simply return s1)
src/string/memmove.c
Outdated
} | ||
else | ||
{ | ||
memcpy(s1, s2, n); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (; n > 0; n--)
{
*cs1++ = *cs2++
}
src/string/memcmp.c
Outdated
char first = cs1[i]; | ||
char second = cs2[i]; | ||
if (first != second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this two variables ? they are uneeded, i is also uneeded (you can do if (*cs1 != *cs2)
)
src/string/strncmp.c
Outdated
int | ||
strncmp(const char *s1, const char *s2, size_t n) | ||
{ | ||
return (memcmp(s1, s2, n)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to be implemented
Hello, I added those functions to the standard library (following their respective descriptions here).
string.h
stddef.h
math.h
#3 #5 #9