diff options
Diffstat (limited to '')
-rw-r--r-- | mat/euler/13/prog.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/mat/euler/13/prog.c b/mat/euler/13/prog.c new file mode 100644 index 0000000..164e030 --- /dev/null +++ b/mat/euler/13/prog.c @@ -0,0 +1,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; +} |