Created
October 27, 2022 10:06
-
-
Save Unam3dd/c84ed1f615afa595b76c6ba2b1d853c0 to your computer and use it in GitHub Desktop.
Trol Incrementation and ft_atoi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int ft_atoi(char *str) | |
{ | |
long long to_dec = 0; | |
int neg = 1; | |
while (!(*str ^ ' ') || (*str >= '\t' && *str <= '\r')) | |
str = (char *)-~(unsigned long long)str; // Wtff dude | |
while ((!(*str ^ '+') || !(*str ^ '-'))) | |
if (!(*str++ ^ '-')) | |
neg = ~(neg - 1); | |
while (*str >= '0' && *str <= '9') | |
to_dec = (to_dec << 1) + (to_dec << 3) + (*str++ & 0xF); | |
if (to_dec > 0x7FFFFFFF || to_dec > -0x80000000) return (0); | |
return (to_dec * neg); | |
} | |
int main(int ac, char **av) | |
{ | |
if (ac < 2) | |
return (1); | |
unsigned char buf[] = "hello"; | |
char *ptr = buf; | |
unsigned long long tmp; | |
printf("%d\n", ft_atoi(av[1])); | |
printf("%s\n", ptr); | |
tmp = -~(unsigned long long)ptr; | |
ptr = (char *)tmp; | |
printf("%s\n", ptr); | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment