Libft
Custom implementation of core libc functions with additional utility helpers.
Loading...
Searching...
No Matches
Conversion Functions

String/number conversion utilities. More...

Functions

int ft_atoi (const char *str)
 Converts a string to an integer.
 
long ft_atol (const char *str)
 Converts a string to a long integer.
 
pid_t ft_atopid (const char *str)
 Converts a string to a pid_t.
 
size_t ft_atozu (const char *str)
 Converts a string to a size_t.
 
char * ft_itoa (int n)
 Converts an integer to a string.
 
char * ft_utoa (unsigned int n)
 Converts an unsigned integer to a string.
 
char * ft_zutoa (size_t n)
 Converts a size_t to a string.
 
char * ft_ltoa (long n)
 Converts a long integer to a string.
 
char * ft_pidtoa (pid_t n)
 Converts a pid_t to a string.
 
char * ft_ultoa_base (unsigned long n, const char *base)
 Converts an unsigned long to a string in a given base.
 
bool parse_int (char *s, int *out)
 Parses a string to an integer with overflow detection.
 
bool parse_long (char *s, long *out)
 Parses a string to a long with overflow detection.
 

Detailed Description

String/number conversion utilities.

Functions to convert between strings and numeric types.

Function Documentation

◆ ft_atoi()

int ft_atoi ( const char *  str)

Converts a string to an integer.

Parameters
strString to convert.
Returns
The converted integer value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_atol()

long ft_atol ( const char *  str)

Converts a string to a long integer.

Parameters
strString to convert.
Returns
The converted long value.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_atopid()

pid_t ft_atopid ( const char *  str)

Converts a string to a pid_t.

Parameters
strString to convert.
Returns
The converted pid_t value.
Here is the call graph for this function:

◆ ft_atozu()

size_t ft_atozu ( const char *  str)

Converts a string to a size_t.

Note
Skips leading whitespace and accepts an optional leading '+'.
Warning
Returns SIZE_MAX on overflow.
Parameters
strString to convert.
Returns
The converted size_t value.
Here is the call graph for this function:

◆ ft_itoa()

char * ft_itoa ( int  n)

Converts an integer to a string.

Note
Caller owns the returned string and must free it.
Parameters
nInteger to convert.
Returns
Newly allocated string (owned), or NULL on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_ltoa()

char * ft_ltoa ( long  n)

Converts a long integer to a string.

Note
Caller owns the returned string and must free it.
Parameters
nLong integer to convert.
Returns
Newly allocated string (owned), or NULL on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_pidtoa()

char * ft_pidtoa ( pid_t  n)

Converts a pid_t to a string.

Note
Caller owns the returned string and must free it.
Parameters
npid_t value to convert.
Returns
Newly allocated string (owned), or NULL on failure.
Here is the call graph for this function:

◆ ft_ultoa_base()

char * ft_ultoa_base ( unsigned long  n,
const char *  base 
)

Converts an unsigned long to a string in a given base.

Note
Caller owns the returned string and must free it.
Parameters
nNumber to convert.
baseString representing the base characters (borrowed, >= 2 chars).
Returns
Newly allocated string (owned), or NULL on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_utoa()

char * ft_utoa ( unsigned int  n)

Converts an unsigned integer to a string.

Note
Caller owns the returned string and must free it.
Parameters
nUnsigned integer to convert.
Returns
Newly allocated string (owned), or NULL on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ft_zutoa()

char * ft_zutoa ( size_t  n)

Converts a size_t to a string.

Note
Caller owns the returned string and must free it.
Parameters
nValue to convert.
Returns
Newly allocated string (owned), or NULL on failure.
Here is the call graph for this function:

◆ parse_int()

bool parse_int ( char *  s,
int *  out 
)

Parses a string to an integer with overflow detection.

Accepts an optional leading '+' or '-' sign followed by digits. Returns false if the string is empty, contains non-digit characters, or the value would overflow an int.

Parameters
sString to parse (borrowed).
outPointer to store the parsed integer (modified on success).
Returns
true on success, false if parsing failed or value out of range.

◆ parse_long()

bool parse_long ( char *  s,
long *  out 
)

Parses a string to a long with overflow detection.

Accepts an optional leading '+' or '-' sign followed by digits. Returns false if the string is empty, contains non-digit characters, or the value would overflow a long.

Parameters
sString to parse (borrowed).
outPointer to store the parsed long (modified on success).
Returns
true on success, false if parsing failed or value out of range.