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.
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_ltoa (long n)
 Converts a long integer 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.

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_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_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:

◆ 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.