ft_atoi
Subject
Understandable explanation
The atoi()
function converts a string to its int
representation.
Some things that the atoi()
function does are not clearly said in the man. I'll quickly list them here.
The string passed as parameter may begin with an arbitrary number of whitespaces as determined by
isspace(3)
After the arbitrary number of whitespaces, there can be one single optional '+' or '-' sign
The remainder of the string will be converted to an int, stopping at the first character which is not a valid digit in the given base (in our case we only need to manage base 10, so the valid digits are 0-9)
I talked about the isspace(3)
function, what is that function ? It works the same way as the isdigit
, isalpha
, etc. but returning a non-zero value when the character is one of the following
To make it easier, will be coding the isspace(3)
function as a static helper function for our atoi(3)
function.
Hints
Commented solution
Last updated