-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathop_code1.c
More file actions
76 lines (69 loc) · 1.54 KB
/
op_code1.c
File metadata and controls
76 lines (69 loc) · 1.54 KB
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 "holberton.h"
/**
* op_char - print output based on variadic input
* @valist: tool to grab next item out of variable length list
* Return: Number chars sent to stdout (should be 1)
**/
int op_char(va_list valist)
{
_putchar(va_arg(valist, int));
return (1);
}
/**
* op_int - print output based on variadic input
* @valist: tool to grab next item out of variable length list
* Return: Number of chars sent to stdout
**/
int op_int(va_list valist)
{
int count;
char s[30];
int n = va_arg(valist, int);
count = itoa(n, s);
_putstr(s);
return (count);
}
/**
* op_float - print output based on variadic input
* @valist: tool to grab next item out of variable length list
* Return: Number of chars sent to stdout
**/
int op_float(va_list valist)
{
UNUSED(valist);
/* printf("%f", va_arg(valist, double)); */
fflush(stdout);
return (0); /* TODO: return proper char chount */
}
/**
* op_percent - 2nd consecutive % occurs - do nothing!
* @valist: var of type va_list is accepted, but nothing is done ...
* Return: # of characters sent to stdout
**/
int op_percent(va_list valist)
{
UNUSED(valist);
_putchar('%');
return (1);
}
/**
* op_string - print output based on variadic input
* @valist: tool to grab next item out of variable length list
* Return: # of chars sent to stdout
**/
int op_string(va_list valist)
{
char *str;
int i;
char *nil = "(null)";
str = _strdup(va_arg(valist, char*));
if (str)
{
for (i = 0; str[i]; i++)
_putchar(str[i]);
/* return (i - 1); */
return (i);
}
write(1, nil, 6);
return (6);
}