-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstdio.c
More file actions
68 lines (54 loc) · 1.2 KB
/
Copy pathstdio.c
File metadata and controls
68 lines (54 loc) · 1.2 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
#include <libc.h>
#include <stdio.h>
/* Funcio print que va escrivint el buffer mitjançant un write
de 256 en 256 bytes fins que troba el caràcter \0. Retorna
el numero de caracters escrits.*/
int
printf (char *buffer)
{
int i = 0, written = 0;
while (buffer[i] != '\0')
i++;
/* buff_d = n de vegades que s'ha de fer un write de 256 bytes
buff_r = n de bytes que queden al final del buffer < 256 bytes
*/
int buff_d = i / 256;
int buff_r = i % 256;
for (i = 0; i < buff_d; i++)
{
buffer = buffer + (i * 256 * sizeof (char));
written = written + write (1, buffer, 256);
}
buffer = buffer + (i * 256 * sizeof (char));
if (buff_r != 0)
written = written + write (1, buffer, buff_r);
return written;
}
void
printint (int i)
{
char buffer[11] =
{ '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' };
itoa (i, buffer);
printf (buffer);
}
void
itoa (int n, char *buffer)
{
int ndigits = n;
int i = 0;
if (n == 0)
buffer[0] = '0';
/* Comptem el nombre de digits */
while (ndigits > 0)
{
i++;
ndigits /= 10;
}
while (i > 0)
{
buffer[i - 1] = (n % 10) + '0';
n /= 10;
i--;
}
}