#include #include #include // we don't need math, as long as we have string xD #include #define ZACETNA_VELIKOST 128 #define DISABLE_LIB_TESTS #include 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; }