Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* ft_atoi.c :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: sgusache <sgusache@student.42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2018/11/09 12:56:06 by sgusache #+# #+# */
- /* Updated: 2018/11/13 18:56:27 by sgusache ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include <stdio.h>
- #include <stdlib.h>
- int ft_atoi(char *str)
- {
- int i = 0;
- int sign = 1;
- int number = 0;
- if(!str)
- return (0);
- while (str[i]==' ' || str[i]=='\t'|| str[i] =='\n'||str[i]=='\r'||str[i]=='\f'||str[i]=='\v'|| str[i]=='+')
- i++;
- if (str[i] == '-')
- {
- sign = -1;
- i++;
- }
- while (str[i]>= '0' && str[i] <= '9')
- {
- if (str[i] >= '0' && str[i] <= '9')
- {
- number *= 10;
- number += str[i] - '0';
- }
- else
- break ;
- i++;
- }
- return ((sign == -1) ? (-number) : (number));
- }
- int main(int argc, char **argv)
- {
- if(argc != 2)
- return 0;
- printf("RESULT OF MY FUNC = %d\n",ft_atoi(argv[1]));
- printf("lIB result = %d\n",atoi(argv[1]));
- //ft_putnbr(ft_atoi(argv[1]));
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement