summaryrefslogtreecommitdiff
path: root/other/burneye2/testcases/1-hello-world/hello-write.c
blob: 3a03afd45d87d9a8d165a88c3c52b144bd3aec06 (plain)
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

#include <unistd.h>
#include <string.h>

void output_num (char *str, int num);


int
main (int argc, char *argv[])
{
	int	n;


	for (n = 0 ; n < 5 ; ++n)
		output_num ("hello: ", n);
}


void
output_num (char *str, int num)
{
	char	numstr[12];
	int	nstrp;


	write (1, str, strlen (str));

	numstr[11] = '\0';
	nstrp = 10;
	if (num == 0)
		numstr[nstrp--] = '0';

	for ( ; num != 0 && nstrp >= 0 ; --nstrp) {
		numstr[nstrp] = num % 10 + '0';
		num = num / 10;
	}
	write (1, &numstr[nstrp] + 1, 10 - nstrp);

	write (1, "\n", 1);
}