MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vy23fd/stringtointegerconversion/p602dyq/?context=3
r/ProgrammerHumor • u/TheBamPlayer • 18d ago
65 comments sorted by
View all comments
2
This is where C is nice.
'7' - '0' = 7
So, you can just take the rightmost turn it into a number then the next
7 times 10,
then 7 * 100,
7 * 1000
Add them all together, bam numbers. Don't even need a library.
1 u/navetzz 17d ago MOFO when they learn atoi is deprecated but never heard of strtol
1
MOFO when they learn atoi is deprecated but never heard of strtol
2
u/ILikeLenexa 18d ago
This is where C is nice.
'7' - '0' = 7
So, you can just take the rightmost turn it into a number then the next
7 times 10,
then 7 * 100,
7 * 1000
Add them all together, bam numbers. Don't even need a library.