forked from Carolinacapote/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintf_functions.c
More file actions
77 lines (67 loc) · 939 Bytes
/
printf_functions.c
File metadata and controls
77 lines (67 loc) · 939 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <stdarg.h>
#include "shell.h"
/**
* print_string - print string
* @arguments: va_list
* Return: string
*/
int print_string(va_list arguments)
{
char *str;
int i = 0;
str = va_arg(arguments, char *);
if (str == NULL)
{
str = "(null)";
}
for (; *str; str++)
{
_putchar(*str);
i++;
}
return (i);
}
/**
* print_character - print character
* @arguments: va_list
* Return: character
*/
int print_character(va_list arguments)
{
int x = 0;
x = va_arg(arguments, int);
_putchar(x);
return (1);
}
/**
* print_integer - print integer and digit
* @arguments: va_list
* Return: int
*/
int print_integer(va_list arguments)
{
int i, d, length;
unsigned int x;
i = va_arg(arguments, int);
d = 1;
length = 0;
if (i < 0)
{
length = length + _putchar('-');
x = i * -1;
}
else
{
x = i;
}
while (x / d > 9)
d = d * 10;
while (d != 0)
{
length = length + _putchar('0' + x / d);
x = x % d;
d = d / 10;
}
return (length);
}