commit
This commit is contained in:
39
C_04/git_old/ex03/ft_atoi.c
Normal file
39
C_04/git_old/ex03/ft_atoi.c
Normal 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);
|
||||
}
|
||||
30
C_04/git_old/ex03/main.c
Normal file
30
C_04/git_old/ex03/main.c
Normal 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);
|
||||
}
|
||||
8
C_04/git_old/ex03/main.sh
Executable file
8
C_04/git_old/ex03/main.sh
Executable 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
|
||||
Reference in New Issue
Block a user