# HG changeset patch # User meillo@marmaro.de # Date 1202827988 -3600 # Node ID 8e34daa80f64d2b23c82c95be83a809333c8e46f # Parent 8a8da74530dd93019245208d22e3a12568da37f6 input is now read from file again (because of input node) diff -r 8a8da74530dd -r 8e34daa80f64 baum.c --- a/baum.c Sat Feb 09 17:26:05 2008 +0100 +++ b/baum.c Tue Feb 12 15:53:08 2008 +0100 @@ -132,7 +132,7 @@ /* read input */ -void read_input() { +void read_input(char* filename) { int c; int indent; char name[256]; @@ -140,6 +140,7 @@ int last_indent; struct Node* last_node; struct Node* node; + FILE* file; indent = 0; strcpy(name, ""); @@ -147,10 +148,11 @@ last_indent = -1; root = newNode("blackhole", 0); last_node = root; + file = fopen(filename, "r"); - while ((c = getchar()) != EOF) { + while ((c = getc(file)) != EOF) { if (c == '#') { /* comment */ - while ((c = getchar()) != '\n') { + while ((c = getc(file)) != '\n') { } } @@ -186,7 +188,7 @@ if (c >= 'a' && c <= 'z') { /* name */ int i = 1; name[0] = (char) c; - while ((c = getchar()) != '(') { + while ((c = getc(file)) != '(') { name[i] = (char) c; i++; if (i > 255) { @@ -197,18 +199,20 @@ } if (c == '(') { /* value */ - scanf("%d)", &value); + fscanf(file, "%d)", &value); } } + fclose(file); + } /* main */ int main(int argc, char* argv[]) { unsigned char shell_return = 0; - read_input(); + read_input("./input_sum3input"); printTree(root); shell_return = action(root);