Skip to content
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

Merged
merged 16 commits into from
Jul 24, 2021
Merged

Standard library #11

merged 16 commits into from
Jul 24, 2021

Conversation

Wafelack
Copy link
Contributor

Hello, I added those functions to the standard library (following their respective descriptions here).

string.h

  • strcat
  • stncat
  • memset
  • memcmp
  • strncmp
  • strcmp
  • memmove
  • memcpy
  • strlen

stddef.h

  • NULL
  • size_t

math.h

  • sqrt

#3 #5 #9

include/ctype.h Outdated
@@ -1,5 +1,5 @@
#ifndef _CTYPE_H
# define _CTYPE_H 1
Copy link
Member

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/errno.h Show resolved Hide resolved
include/math.h Outdated
@@ -0,0 +1,11 @@
#ifndef _MATH_H
#define _MATH_H 1
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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
Comment on lines 29 to 34
size_t len = strlen(s1);
if (len > strlen(s2))
{
len = strlen(s2);
}
return (strncmp(s1, s2, len));
Copy link
Member

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

Comment on lines 6 to 12
char *cs = (char *)s;
unsigned char cc = (unsigned char)c;
size_t i = 0;
for (; i < n; i++)
{
cs[i] = cc;
}
Copy link
Member

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);
}

Comment on lines 3 to 10
size_t
strlen(const char *s)
{
size_t i = 0;
while (s[i++] != 0)
;
return (i - 1);
}
Copy link
Member

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);


cs1 = (char *)s1;
cs2 = (const char *)s2;
if (cs2 + n >= cs1)
Copy link
Member

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)

}
else
{
memcpy(s1, s2, n);
Copy link
Member

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++
}

Comment on lines 12 to 14
char first = cs1[i];
char second = cs2[i];
if (first != second)
Copy link
Member

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))

int
strncmp(const char *s1, const char *s2, size_t n)
{
return (memcmp(s1, s2, n));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to be implemented

@d0p1s4m4 d0p1s4m4 merged commit a909084 into cute-engineering:main Jul 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants