Browse Source

correct3

master
Elouan MARTINET 4 years ago
parent
commit
5957c7ebab
  1. 14
      ft_itoa.c
  2. 18
      ft_memmove.c
  3. 29
      ft_strlcat.c
  4. 19
      ft_strtrim.c

14
ft_itoa.c

@ -16,7 +16,9 @@ static size_t ft_itoa_len(int n)
{
size_t r;
r = 1;
if (n == 0)
return (1);
r = 0;
if (n < 0)
r++;
while (n)
@ -30,6 +32,7 @@ static size_t ft_itoa_len(int n)
char *ft_itoa(int n)
{
size_t l;
size_t e;
char *r;
l = ft_itoa_len(n);
@ -37,10 +40,15 @@ char *ft_itoa(int n)
return (NULL);
r[l] = '\0';
if (n < 0)
{
r[0] = '-';
while (n)
e = 1;
}
else
e = 0;
while (l-- > e)
{
r[--l] = '0' + n % 10;
r[l] = '0' + n % 10 * (n < 0 ? -1 : 1);
n /= 10;
}
return (r);

18
ft_memmove.c

@ -16,6 +16,7 @@ void *ft_memmove(void *dst, const void *src, size_t len)
{
char *csrc;
char *cdst;
size_t i;
if (src == dst)
return (dst);
@ -23,13 +24,18 @@ void *ft_memmove(void *dst, const void *src, size_t len)
cdst = (char *)dst;
if (src < dst)
{
csrc += len;
cdst += len;
while (len--)
*(cdst--) = *(csrc--);
i = len;
while (i-- > 0)
cdst[i] = csrc[i];
}
else
while (len--)
*(cdst++) = *(csrc++);
{
i = 0;
while (i < len)
{
cdst[i] = csrc[i];
i++;
}
}
return (dst);
}

29
ft_strlcat.c

@ -14,22 +14,23 @@
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dsti;
size_t dstlen;
size_t srclen;
size_t srci;
size_t dsti;
dsti = ft_strnlen(dst, size);
if (dsti == size)
return (size);
srci = 0;
while (dsti < size)
dstlen = ft_strnlen(dst, size);
srclen = ft_strlen(src);
if (dstlen < size)
{
dst[dsti] = src[srci];
if (src[srci] == '\0')
return (dsti - 1);
dsti++;
srci = 0;
dsti = dstlen;
while (dsti < size && srci < srclen)
dst[dsti++] = src[srci++];
if (dsti < size)
dst[dsti] = '\0';
else
dst[size - 1] = '\0';
}
dst[size - 1] = '\0';
while (src[srci] != '\0')
srci++;
return (size + srci - 1);
return (dstlen + srclen);
}

19
ft_strtrim.c

@ -24,12 +24,21 @@ char *ft_strtrim(char const *s)
size_t i;
char *r;
end = ft_strlen(s);
start = 0;
while (s[start] && ft_strtrim_space(s[start]))
start++;
end = start;
while (s[end] && !ft_strtrim_space(s[end]))
end++;
if (end > 0)
{
while (s[start] && ft_strtrim_space(s[start]))
start++;
if (s[start] == '\0')
start = end;
else
{
while (--end > 0 && ft_strtrim_space(s[end]))
(void)0;
end++;
}
}
if (!(r = (char *)malloc(end - start + 1)))
return (NULL);
i = 0;

Loading…
Cancel
Save