0
0
This commit is contained in:
Guy Baconniere
2021-08-16 13:27:55 +02:00
parent c665b6c546
commit 0909750997
21 changed files with 431 additions and 14 deletions

View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/13 12:46:22 by gbaconni #+# #+# */
/* Updated: 2021/08/13 14:58:30 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int nb;
int s;
int i;
nb = 0;
s = 0;
i = 0;
while (str[i] != '\0')
{
if (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r'))
s += 0;
else if (str[i] == '+')
s++;
else if (str[i] == '-')
s--;
else if (str[i] >= '0' && str[i] <= '9')
nb = nb * 10 + str[i] - '0';
else
break ;
i++;
}
if (s < 0)
nb *= -1;
return (nb);
}

View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/13 12:46:41 by gbaconni #+# #+# */
/* Updated: 2021/08/13 13:58:09 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int ft_atoi(char *str);
int main(void)
{
char str[32];
int result;
printf("Input String [31]: ");
scanf("%s", str);
result = ft_atoi(str);
printf("str=%s result=%d (ft_atoi)\n", str, result);
return (0);
}

View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
#norminette -R CheckForbiddenSourceHeader ft_*.c
norminette -R CheckForbiddenSourceHeader
gcc -Wall -Wextra -Werror -o a.out *.c
echo $(basename $PWD):
./a.out
rm -f a.out