forked from AngelPedroza/printf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_characters_functions.c
91 lines (86 loc) · 2.34 KB
/
print_characters_functions.c
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
84
85
86
87
88
89
90
91
#include "holberton.h"
/**
* _printchar - move the chararcter into the buffer.
*
* @valist: My list of arguments.
* @buffer: My buffer is a malloc declaration that I will use for print all.
* @count: This is the parameter to count the position that should put
* in the buffer.
* Return: Always is 0.
*/
int _printchar(va_list valist, char *buffer, int *count)
{
char c;
c = va_arg(valist, int);
moveinto_buffer(buffer, c, count);
return (0);
}
/**
* printstr - move each element of a string into a buffer.
*
* @valist: My list of arguments.
* @buffer: My buffer is a malloc declaration that I will use for print all.
* @count: This is the parameter to count the position that should put
* in the buffer.
* Return: Always is 0.
*/
int printstr(va_list valist, char *buffer, int *count)
{
int it, len;
char *s;
s = va_arg(valist, char *);
len = _strlen(s);
for (it = 0; it < len; it++)
{
moveinto_buffer(buffer, s[it], count);
}
return (0);
}
/**
* PPS - Print a % if you have %%.
*
* @buffer: My buffer is a malloc declaration that I will use for print all.
* @count: This is the parameter to count the position that should put
* in the buffer.
* Return: Always is 0.
*/
int PPS(char *buffer, int *count)
{
moveinto_buffer(buffer, '%', count);
return (0);
}
/**
* capitalize - capitalizes a string
*
* @valist: the argument list to take the string from
* @buffer: My buffer is a malloc declaration that I will use for print all.
* @count: This is the parameter to count the position that should put
* in the buffer.
* Return: Always is 0.
*/
int capitalize(va_list valist, char *buffer, int *count)
{
int it, i, j, len;
char *s, *d;
char upperalpha[] = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ";
char loweralpha[] = "abcdefghijklmnñopqrstuvwxyz";
s = va_arg(valist, char *);
len = _strlen(s);
d = malloc(len);
for (j = 0; s[j] != '\0'; j++)
{
for (i = 0; loweralpha[i] != '\0'; i++)
{
if (s[j] == loweralpha[i])
d[j] = upperalpha[i];
if (s[j] == upperalpha[i])
d[j] = upperalpha[i];
}
}
for (it = 0; it < len; it++)
{
moveinto_buffer(buffer, d[it], count);
}
free(d);
return (0);
}