summaryrefslogtreecommitdiffstats
path: root/mat/euler/13/prog.c
blob: 164e030b857209925de53ad1f3b8d09b9793db92 (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
#include <stdio.h>
#include <stdlib.h>
#include <math.h> // we don't need math, as long as we have string xD
#include <string.h>
#define ZACETNA_VELIKOST 128
#define DISABLE_LIB_TESTS
#include <dodaj.c>
int main (int argc, char ** argv) {
	fprintf(stderr, "program bere številke, ločene z LF, iz STDIN, ter jih sešteva.\n");
	char c = fgetc(stdin);
	char s[] = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
	size_t l = strlen(s);
	// at this point I should mention that the the time is finite.
	size_t velikost_b = ZACETNA_VELIKOST;
	char * b = malloc(sizeof(char)*velikost_b);
	unsigned int p = 0; // zaPisanih znakov v Buffer
	while (c != EOF) {
		if (c - '0' >= 0 && c - '0' <= 9) {
			if (p + 3 >= velikost_b - 3) { // off by one can't happen now xD
				velikost_b = velikost_b * 2;
				char * b = realloc(b, sizeof(char)*velikost_b);
			}
			b[p++] = c;
		}
		if (c == '\n') {
			b[p] = '\0';
			dodaj (b, s, p, l);
			fprintf(stderr, "dodal %s in dobil %s.\n", b, s);
			p = 0;
		}
		continue_while:
		c = fgetc(stdin);
	}
	fprintf(stdout, "seštevek številk je %s\n", s);
	return 0;
}