-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathman_3_printf
More file actions
83 lines (71 loc) · 3.23 KB
/
man_3_printf
File metadata and controls
83 lines (71 loc) · 3.23 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
77
78
79
80
81
82
83
.\" Manpage for _printf
.TH man 8 "26 February 2018" "1.0" "_printf man page"
.SH NAME
_printf \- format and print data
.SH SYNOPSIS
_printf FORMAT [ARGUMENT]
_printf OPTION
.SH DESCRIPTION
The _printf utility formats and prints its arguments, after the first format argument, under control of the format. The format is a character string which contains three types of objects: plain characters, which are simply copied to standard output, character escape sequences which are converted and copied to the standard output, and format specifications, each of which causes printing of the next argument.
Print ARGUMENT(s) according to FORMAT, or execute according to OPTION.
FORMAT controls the output as in C _printf. Interpreted sequences are:
\" double quote
\\ backslash
%% a single %
Conversion specifiers
A character that specifies the type of conversion to be applied. The conversion specifiers and their meanings are:
d, i Integers of base 10; The int argument is converted to signed decimal notation.
c Character;
s String of characters;
.SH RETURN VALUE
Upon successful return, this function returns the number of characters printed (excluding the null byte used to end output to strings). Upon failure it returns a negative value.
int _printf(const char *format, ...)
{
data_type specifier[] = {
{"c", print_char}, {"s", print_str}, {"d", print_dec},
{"i", print_dec}, {NULL, NULL}
};
va_list args; int spec_i = 0, place = 0, len = 0, len2 = 0, smark = 1;
if (format == NULL)
return (-1);
va_start(args, format);
for (; format[place] != '\0'; place++)
{
if ((format[place] != 37) && (format[place] != 92))
{
printchar(format[place]); len++;
}
else if (format[place] == 92)
handlebackslash(format, place, len);
else if (format[place] == 37)
{
if (format[place + smark] == 37)
{
printchar(37); len++; place++;
}
else if (format[place + smark] != 'c' && format[place + smark] != 's'
&& format[place + smark] != 'd' && format[place + smark] != 'i')
{
printchar(format[place]); len++;
}
else
{
for (spec_i = 0; specifier[spec_i].fmt_spec != NULL; spec_i++)
if (format[place + smark] == *specifier[spec_i].fmt_spec)
{
len2 = specifier[spec_i].f(args);
len += len2;
}
place++;
}
}
}
va_end(args);
return (len);
}
.SH SEE ALSO
printf
.SH BUGS
About to discover.
.SH AUTHOR
Written by: Alex Allen, Elena Serebryakova