ft_atoi()
This commit is contained in:
parent
3043d38bf0
commit
fc301f82aa
3 changed files with 90 additions and 2 deletions
82
ft_atoi_test.c
Normal file
82
ft_atoi_test.c
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi_test.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: lalgarra <lalgarra@student.42madrid.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/10/07 18:36:33 by lalgarra #+# #+# */
|
||||
/* Updated: 2025/10/07 18:49:30 by lalgarra ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static void test(char *prefix, char buff[])
|
||||
{
|
||||
int res;
|
||||
int fd;
|
||||
|
||||
fd = STDOUT_FILENO;
|
||||
ft_putstr_fd(prefix, fd);
|
||||
ft_putstr_fd("buff:[", fd);
|
||||
ft_putstr_fd(buff, fd);
|
||||
res = ft_atoi(buff);
|
||||
ft_putstr_fd("], result:[", fd);
|
||||
ft_putnbr_fd(res, fd);
|
||||
ft_putendl_fd("]", fd);
|
||||
}
|
||||
|
||||
static void zero(char buff[])
|
||||
{
|
||||
ft_bzero(buff, 128);
|
||||
}
|
||||
|
||||
static void do_test1(char buff[])
|
||||
{
|
||||
zero(buff);
|
||||
ft_strlcpy(buff, "+350", 4);
|
||||
test("test 1: ", buff);
|
||||
}
|
||||
|
||||
static void do_test2(char buff[])
|
||||
{
|
||||
zero(buff);
|
||||
ft_strlcpy(buff, "+-50", 5);
|
||||
test("test 2: ", buff);
|
||||
}
|
||||
|
||||
static void do_test3(char buff[])
|
||||
{
|
||||
zero(buff);
|
||||
ft_strlcpy(buff, " -3", 5);
|
||||
test("test 3: ", buff);
|
||||
}
|
||||
|
||||
static void do_test4(char buff[])
|
||||
{
|
||||
zero(buff);
|
||||
ft_strlcpy(buff, " \t\v\f\r\n +1367442", 20);
|
||||
test("test 4: ", buff);
|
||||
}
|
||||
|
||||
static void do_test5(char buff[])
|
||||
{
|
||||
zero(buff);
|
||||
ft_strlcpy(buff, " -+50", 5);
|
||||
test("test 5: ", buff);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buff[128];
|
||||
|
||||
do_test1(buff);
|
||||
do_test2(buff);
|
||||
do_test3(buff);
|
||||
do_test4(buff);
|
||||
do_test5(buff);
|
||||
return (0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue