ft_calloc(). Norminette

This commit is contained in:
lalgarra 2025-10-05 13:48:30 +02:00
parent 41ed119416
commit d64354612b
9 changed files with 154 additions and 27 deletions

View file

@ -6,19 +6,19 @@
# By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ # # By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2025/10/03 18:03:12 by lalgarra #+# #+# # # Created: 2025/10/03 18:03:12 by lalgarra #+# #+# #
# Updated: 2025/10/04 16:57:22 by lalgarra ### ########.fr # # Updated: 2025/10/05 13:30:04 by lalgarra ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
# Location of your libft.a; it must already exist # Location of your libft.a; it must already exist
#LIBDIR = ../repo_libft_algarra LIBDIR = ../repo_libft_algarra
LIBDIR = ../vogsphere_repo #LIBDIR = ../vogsphere_repo
CFLAGS += -Wall -Wextra -Werror -g3 -iquote $(LIBDIR) CFLAGS += -Wall -Wextra -Werror -g3 -iquote $(LIBDIR)
TESTS := ft_isalpha_test ft_isdigit_test ft_isalnum_test ft_isascii_test \ TESTS := ft_isalpha_test ft_isdigit_test ft_isalnum_test ft_isascii_test \
ft_isprint_test ft_toupper_test ft_tolower_test ft_strlen_test \ ft_isprint_test ft_toupper_test ft_tolower_test ft_strlen_test \
ft_memset_test ft_bzero_test ft_memcpy_test ft_memset_test ft_bzero_test ft_memcpy_test ft_calloc_test
%_test : %_test.c %_test : %_test.c
$(CC) $(CFLAGS) $*_test.c -L$(LIBDIR) -lft -o $*_test $(CC) $(CFLAGS) $*_test.c -L$(LIBDIR) -lft -o $*_test

View file

@ -0,0 +1,7 @@
test 1: pos. 0, value: 0
test 1: pos. 1, value: 0
test 1: pos. 2, value: 0
test 1: pos. 3, value: 0
test 1: pos. 4, value: 0
test 2: buflen = 0; buff == NULL: 0
test 3: size= 0; buff == NULL: 0

64
ft_calloc_test.c Normal file
View file

@ -0,0 +1,64 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/05 13:21:43 by lalgarra #+# #+# */
/* Updated: 2025/10/05 13:46:25 by lalgarra ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdio.h>
#include <string.h>
static void do_test3(char *prefix)
{
int *buff;
size_t buflen;
size_t size;
buflen = 5;
size = 0;
buff = ft_calloc(buflen, size);
printf("%ssize= %lu; buff == NULL: %i\n", prefix, size, buff == NULL);
free(buff);
}
static void do_test2(char *prefix)
{
int *buff;
size_t buflen;
buflen = 0;
buff = ft_calloc(buflen, sizeof(int));
printf("%sbuflen = %lu; buff == NULL: %i\n", prefix, buflen, buff == NULL);
free(buff);
}
static void do_test1(char *prefix)
{
int *buff;
size_t buflen;
size_t idx;
buflen = 5;
buff = ft_calloc(buflen, sizeof(int));
idx = 0;
while (idx < buflen)
{
printf("%spos. %lu, value: %i\n", prefix, idx, buff[idx]);
idx++;
}
free(buff);
}
int main(void)
{
do_test1("test 1: ");
do_test2("test 2: ");
do_test3("test 3: ");
return (0);
}

View file

@ -1,13 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/05 13:35:25 by lalgarra #+# #+# */
/* Updated: 2025/10/05 13:35:54 by lalgarra ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
#include<stdio.h> #include <stdio.h>
int main(void) int main(void)
{ {
int c; int c;
for (c = 0; c < 256; c++) c = 0;
while (c < 256)
{ {
printf("'%c' (%i); isalnum(c): %i\r\n", c, c, ft_isalnum(c)); printf("'%c' (%i); isalnum(c): %i\r\n", c, c, ft_isalnum(c));
c++;
} }
return (0); return (0);
} }

View file

@ -1,13 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/05 13:30:41 by lalgarra #+# #+# */
/* Updated: 2025/10/05 13:31:38 by lalgarra ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
#include<stdio.h> #include <stdio.h>
int main(void) int main(void)
{ {
int c; int c;
for (c = 0; c < 256; c++) c = 0;
while (c < 256)
{ {
printf("'%c' (%i); isalpha(c): %i\r\n", c, c, ft_isalpha(c)); printf("'%c' (%i); isalpha(c): %i\r\n", c, c, ft_isalpha(c));
c++;
} }
return (0); return (0);
} }

View file

@ -1,16 +1,27 @@
/* /* ************************************************************************** */
#include<ctype.h> /* */
*/ /* ::: :::::::: */
/* ft_isascii_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/05 13:33:27 by lalgarra #+# #+# */
/* Updated: 2025/10/05 13:34:20 by lalgarra ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
#include<stdio.h> #include <stdio.h>
int main(void) int main(void)
{ {
int c; int c;
for (c = 0; c < 256; c++) c = 0;
while (c < 256)
{ {
printf("'%c' (%i); isascii(c): %i\r\n", c, c, ft_isascii(c)); printf("'%c' (%i); isascii(c): %i\r\n", c, c, ft_isascii(c));
c++;
} }
return (0); return (0);
} }

View file

@ -1,13 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/05 13:32:43 by lalgarra #+# #+# */
/* Updated: 2025/10/05 13:32:45 by lalgarra ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h" #include "libft.h"
#include<stdio.h> #include <stdio.h>
int main(void) int main(void)
{ {
int c; int c;
for (c = 0; c < 256; c++) c = 0;
while (c < 256)
{ {
printf("'%c' (%i); isdigit(c): %i\r\n", c, c, ft_isdigit(c)); printf("'%c' (%i); isdigit(c): %i\r\n", c, c, ft_isdigit(c));
c++;
} }
return (0); return (0);
} }

View file

@ -6,20 +6,23 @@
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */ /* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/03 18:27:44 by lalgarra #+# #+# */ /* Created: 2025/10/03 18:27:44 by lalgarra #+# #+# */
/* Updated: 2025/10/03 20:17:16 by lalgarra ### ########.fr */ /* Updated: 2025/10/05 13:38:43 by lalgarra ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
#include<stdio.h> #include <stdio.h>
int main(void) int main(void)
{ {
int p1; int p1;
for (p1 = 0; p1 < 256; p1++) p1 = 0;
while (p1 < 256)
{ {
printf("'%c' (%i); isprint(c)!=0: %i\r\n", p1, p1, ft_isprint(p1)!=0); printf("'%c' (%i); isprint(c)!=0: %i\r\n",
p1, p1, ft_isprint(p1) != 0);
p1++;
} }
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */ /* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/10/03 18:27:44 by lalgarra #+# #+# */ /* Created: 2025/10/03 18:27:44 by lalgarra #+# #+# */
/* Updated: 2025/10/04 12:15:34 by lalgarra ### ########.fr */ /* Updated: 2025/10/05 13:35:06 by lalgarra ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -20,7 +20,7 @@ void do_test(const char *buff)
buff, ft_strlen(buff), strlen(buff), ft_strlen(buff) == strlen(buff)); buff, ft_strlen(buff), strlen(buff), ft_strlen(buff) == strlen(buff));
} }
int main(void) int main(void)
{ {
char buff[255]; char buff[255];