-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_print_format.c
More file actions
52 lines (44 loc) · 920 Bytes
/
_print_format.c
File metadata and controls
52 lines (44 loc) · 920 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
#include "main.h"
#include <stdarg.h>
/**
* _print_format - print to stdout with specified format
* @format: conversion specifier
* @args: arguments to be passed
* @sp: length of string
* @si: mathematical sign
* Return: length of output
*/
int _print_format(char format, va_list args, int sp, int si)
{
int n = 0;
static char result[SIZE];
switch (format)
{
case 'c':
_putchar(va_arg(args, int));
n++;
break;
case 's':
n += _print_string(va_arg(args, char *), sp, si);
break;
case '%':
_putchar('%');
n++;
break;
case 'd':
_itoa(va_arg(args, int), result);
n += _print_string(result, sp, si * 3);
break;
case 'b':
_itoa(to_binary(va_arg(args, int)), result);
n += _print_string(result, sp, si * 3);
break;
case 'i':
_itoa(va_arg(args, int), result);
n += _print_string(result, sp, si * 3);
break;
default:
break;
}
return (n);
}