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 diff
1.1 --- a/baum.c Sat Feb 09 17:26:05 2008 +0100 1.2 +++ b/baum.c Tue Feb 12 15:53:08 2008 +0100 1.3 @@ -132,7 +132,7 @@ 1.4 1.5 1.6 /* read input */ 1.7 -void read_input() { 1.8 +void read_input(char* filename) { 1.9 int c; 1.10 int indent; 1.11 char name[256]; 1.12 @@ -140,6 +140,7 @@ 1.13 int last_indent; 1.14 struct Node* last_node; 1.15 struct Node* node; 1.16 + FILE* file; 1.17 1.18 indent = 0; 1.19 strcpy(name, ""); 1.20 @@ -147,10 +148,11 @@ 1.21 last_indent = -1; 1.22 root = newNode("blackhole", 0); 1.23 last_node = root; 1.24 + file = fopen(filename, "r"); 1.25 1.26 - while ((c = getchar()) != EOF) { 1.27 + while ((c = getc(file)) != EOF) { 1.28 if (c == '#') { /* comment */ 1.29 - while ((c = getchar()) != '\n') { 1.30 + while ((c = getc(file)) != '\n') { 1.31 } 1.32 } 1.33 1.34 @@ -186,7 +188,7 @@ 1.35 if (c >= 'a' && c <= 'z') { /* name */ 1.36 int i = 1; 1.37 name[0] = (char) c; 1.38 - while ((c = getchar()) != '(') { 1.39 + while ((c = getc(file)) != '(') { 1.40 name[i] = (char) c; 1.41 i++; 1.42 if (i > 255) { 1.43 @@ -197,18 +199,20 @@ 1.44 } 1.45 1.46 if (c == '(') { /* value */ 1.47 - scanf("%d)", &value); 1.48 + fscanf(file, "%d)", &value); 1.49 } 1.50 1.51 } 1.52 1.53 + fclose(file); 1.54 + 1.55 } 1.56 1.57 /* main */ 1.58 int main(int argc, char* argv[]) { 1.59 unsigned char shell_return = 0; 1.60 1.61 - read_input(); 1.62 + read_input("./input_sum3input"); 1.63 printTree(root); 1.64 1.65 shell_return = action(root);