Skip to content
Iva edited this page Sep 27, 2024 · 5 revisions

unsig_number

Calculates the number of digits in an unsigned integer:
Returns the number of digits required to represent the given unsigned integer n in decimal notation.

Original Function:

Library None (Internal helper function)
Signature int unsig_number(unsigned int n);
Parameters n: The unsigned integer to analyze.
Return The number of digits in the unsigned integer n.

Usage Example:

int digits = unsig_number(12345); // Returns 5

Specifics:

Repeatedly divides the number by 10 until it is reduced to 0, counting the divisions.


print_unsig

Prints an unsigned integer to standard output (stdout):
Converts an unsigned integer into its decimal string representation and prints it.

Original Function:

Library <unistd.h>, <stdlib.h>
Signature int print_unsig(unsigned int n);
Parameters n: The unsigned integer to be printed.
Return The number of characters printed.

Usage Example:

int printed = print_unsig(12345); // Prints "12345" and returns 5

Specifics:

If n == 0, it directly prints '0' and returns 1, without further calculations.
Uses unsig_number(n) to calculate the number of digits in the unsigned integer n.
Allocates memory to store the string representation of n. After conversion, the string is printed, and the allocated memory is freed.
Uses write() from <unistd.h> to print the string to standard output.

Top ⬆️ Next ➡️

Clone this wiki locally