aboutsummaryrefslogtreecommitdiffstats
path: root/examples/02-prod.c
blob: 8b7af40de3863cd0b777ed3b6207e2786627f5ce (plain) (blame)
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
/* Calculates the product of $@ */

#include <stdio.h>
#include <stdlib.h>

#include <zahl.h>

int
main(int argc, char *argv[])
{
	z_t prod, factor;
	jmp_buf env;
	char *buf;
	int i;

	if (setjmp(env))
		return zperror(argv[0]), 1;

	zsetup(env);
	zinit(prod);
	zinit(factor);
	zsetu(prod, 1);

	for (i = 1; i < argc; i++) {
		zsets(factor, argv[i]);
		zmul(prod, prod, factor);
	}

	printf("%s\n", buf = zstr(prod, NULL, 0));
	free(buf);

	zfree(factor);
	zfree(prod);
	zunsetup();
	return 0;
}