01-sum.c (475B)
1 /* Calculates the sum of $@ */ 2 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 #include <zahl.h> 7 8 int 9 main(int argc, char *argv[]) 10 { 11 z_t sum, term; 12 jmp_buf env; 13 char *buf; 14 int i; 15 16 if (setjmp(env)) 17 return zperror(argv[0]), 1; 18 19 zsetup(env); 20 zinit(sum); 21 zinit(term); 22 zsetu(sum, 0); 23 24 for (i = 1; i < argc; i++) { 25 zsets(term, argv[i]); 26 zadd(sum, sum, term); 27 } 28 29 printf("%s\n", buf = zstr(sum, NULL, 0)); 30 free(buf); 31 32 zfree(term); 33 zfree(sum); 34 zunsetup(); 35 return 0; 36 }