ft_memset()
This commit is contained in:
parent
ad2fae898b
commit
a60d1e1a87
3 changed files with 75 additions and 2 deletions
57
ft_memset_test.c
Normal file
57
ft_memset_test.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset_test.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/10/03 18:27:44 by lalgarra #+# #+# */
|
||||
/* Updated: 2025/10/04 12:52:11 by lalgarra ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void do_test(const char *buff, size_t n)
|
||||
{
|
||||
void *res;
|
||||
size_t idx;
|
||||
char c1;
|
||||
|
||||
printf("buff: \"%s\", n=%lu\r\n", buff, n);
|
||||
c1 = 'X';
|
||||
res = ft_memset((void *)buff, c1, n);
|
||||
printf("after call: buff: \"%s\", n=%lu\r\n", buff, n);
|
||||
printf("res == buff: %i;", res == buff);
|
||||
idx = 0;
|
||||
while (idx < n)
|
||||
{
|
||||
if (*(buff + idx) != c1)
|
||||
{
|
||||
printf(" pos. %lu not set!!", idx);
|
||||
idx = n;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
if (*(buff + n) == c1)
|
||||
printf(" pos. %lu updated!!", idx);
|
||||
printf("\r\n");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buff[18];
|
||||
|
||||
strcpy(buff, "");
|
||||
do_test(buff, 0);
|
||||
do_test(buff, 3);
|
||||
strcpy(buff, "Iorem ipsum dolor");
|
||||
do_test(buff, 3);
|
||||
strcpy(buff, "Iorem ipsum dolor");
|
||||
do_test(buff, 16);
|
||||
strcpy(buff, "Iorem ipsum dolor");
|
||||
do_test(buff, 17);
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue