#include <stdio.h>
#include <stdlib.h>
//int atoi(const char *str);
int ft_atoi(char *s)
{
int sign;
long r;
r = 0;
sign = 1;
while (*s == 32 || (*s >= 9 && *s <= 13))
s++;
if (*s == '-' || *s == '+')
{
if (*s == '-')
sign = -1;
s++;
}
while (*s >= '0' && *s <= '9')
{
r = r * 10 + *s - '0';
s++;
}
return (sign * (int)r);
}
int main()
{
char str[] = " 1234ab567";
printf("%d\n", atoi(str));
printf("%d\n", ft_atoi(str));
char str1[] = " +01234ab567";
printf("%d\n", atoi(str1));
printf("%d\n", ft_atoi(str1));
char str2[] = "\t+12a34ab567";
printf("%d\n", atoi(str2));
printf("%d\n", ft_atoi(str2));
char str3[] = "12+56434";
printf("%d\n", atoi(str3));
printf("%d\n", ft_atoi(str3));
char str4[] = " ++++++01234ab567";
printf("%d\n", atoi(str4));
printf("%d\n", ft_atoi(str4));
char str5[] = "\t++++12a34ab567";
printf("%d\n", atoi(str5));
printf("%d\n", ft_atoi(str5));
char str6[] = " 12+56434";
printf("%d\n", atoi(str6));
printf("%d\n", ft_atoi(str6));
return (0);
}
To embed this project on your website, copy the following code and paste it into your website's HTML: