Mercurial > baum
changeset 12:8e34daa80f64
input is now read from file again (because of input node)
author | meillo@marmaro.de |
---|---|
date | Tue, 12 Feb 2008 15:53:08 +0100 |
parents | 8a8da74530dd |
children | bf660b45bba9 |
files | baum.c |
diffstat | 1 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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);