-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunsigned
More file actions
31 lines (26 loc) · 777 Bytes
/
Copy pathunsigned
File metadata and controls
31 lines (26 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "main.h"
/**
* print_unsigned - Prints an unsigned number to a buffer.
* @types: The list of arguments passed.
* @buffer: Buffer array to handle print.
*
* Return: The number of chars printed.
*/
int print_unsigned(va_list types, char buffer[])
{
int x = BUFF_SIZE - 2; /* Start index for writing in the buffer */
unsigned long int num = va_arg(types, unsigned long int);
/* Handle the case when the number is 0 */
if (num == 0)
buffer[x--] = '0';
buffer[BUFF_SIZE - 1] = '\0'; /* Null-terminate the buffer */
/* Convert and write the number to the buffer in reverse order */
while (num > 0)
{
buffer[x--] = (num % 10) + '0';
num /= 10;
}
x++;
/* Call the function to write the buffer to a destination */
return (write_unsgnd(x, buffer));
}