๐memset
โ๏ธ ํจ์ ํ๋กํ ํ์
void *memset(void *b, int c, size_t len);
โ๏ธ ํจ์์ ์ญํ : c ๊ฐ(unsigned char ๋ก ๋ณํ๋จ)์ len ๋ฐ์ดํธ ๊ธธ์ด๋งํผ ๋ฌธ์์ด b์ ์ด๋ค.
โ๏ธํจ์ ๋ฐํ๊ฐ
โ๏ธmemset ํจ์์ ์ฒซ ๋ฒ์งธ ์ธ์
โ๏ธ๊ตฌํ
#include "libft.h"
void *ft_memset(void *b, int c, size_t len)
{
size_t i;
i = 0;
while (i < len)
{
*(unsigned char *)(b + i) = (unsigned char)c;
i++;
}
return (b);
}
๐bzero
โ๏ธ ํจ์ ํ๋กํ ํ์
void bzero(void *s, size_t n);
โ๏ธ ํจ์์ ์ญํ : 0 n๋ฐ์ดํธ๋ฅผ s์ ์ด๋ค.
โ๏ธํจ์ ๋ฐํ๊ฐ ์์
โ๏ธ๊ตฌํ
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
size_t i;
i = 0;
if (n == 0)
return ;
while (i < n)
{
*(unsigned char *)(s + i) = 0;
i++;
}
}
๐memchr
โ๏ธ ํจ์ ํ๋กํ ํ์
void *memchr(const void *s, int c, size_t n);
โ๏ธ ํจ์์ ์ญํ : string s์์ ์ฒ์ ๋ํ๋๋ c(unsigned char ๋ก ๋ณํ๋จ)๋ฅผ ์ฐพ๋๋ค.
โ๏ธํจ์ ๋ฐํ๊ฐ
โ๏ธc๋ฅผ s์์ ์ฐพ์ ๊ฒฝ์ฐ, ๊ทธ ์์น๋ฅผ ๊ฐ๋ฆฌํค๋ ํฌ์ธํฐ
โ๏ธ s์ c๊ฐ ์กด์ฌํ์ง ์์ ๊ฒฝ์ฐ, NULL
โ๏ธ๊ตฌํ
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
unsigned char *tmp;
i = 0;
tmp = (unsigned char *)s;
while (i < n)
{
if (tmp[i] == (unsigned char)c)
return (&tmp[i]);
i++;
}
return (NULL);
}
'๐ฐ42์์ธ > libft' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[libft] ft_atoi.c ๊ตฌํ (0) | 2022.02.17 |
---|---|
[libft] ft_memcpy, ft_memmove ๊ตฌํ (0) | 2022.02.16 |
[libft] ft_strncmp, ft_memcmp ๊ตฌํ (0) | 2022.02.14 |
[42์์ธ] libft ์ ๋ฆฌ : ft_strchr, ft_strrchr๊ตฌํ (0) | 2022.02.13 |
[42์์ธ] libft ์ ๋ฆฌ : ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ง๋ค๊ธฐ ์ํ Makefile (0) | 2022.02.11 |