baum
diff baum.c @ 6:ab87b154a96b
first tries for the read input function
author | meillo@marmaro.de |
---|---|
date | Fri, 08 Feb 2008 21:44:07 +0100 |
parents | c202ccccedb5 |
children | 6a6152cf63f7 |
line diff
1.1 --- a/baum.c Fri Feb 08 20:45:17 2008 +0100 1.2 +++ b/baum.c Fri Feb 08 21:44:07 2008 +0100 1.3 @@ -180,9 +180,41 @@ 1.4 } 1.5 1.6 1.7 +/* read input */ 1.8 +void read_input(char* filename) { 1.9 + FILE* fp; 1.10 + char c; 1.11 + char* line; 1.12 + int indent; 1.13 + char* name; 1.14 + int value; 1.15 + 1.16 + fp = fopen(filename, "r"); 1.17 + indent = 0; 1.18 + 1.19 + while ((c = getc(fp)) != EOF) { 1.20 + if (c == ' ' || c == '\t') { 1.21 + indent++; 1.22 + } else if (c == '(') { 1.23 + fscanf(fp, "%d", &value); 1.24 + } else if (c == '\n') { 1.25 + 1.26 + if (strcmp(name, "") != 0) { 1.27 + printf("\nindent: %d\nname: %s\nvalue: %d\n", indent, name, value); 1.28 + } 1.29 + indent = 0; 1.30 + strcpy(name, ""); 1.31 + value = 0; 1.32 + } else { 1.33 + fscanf(fp, "%[a-z]", name); 1.34 + } 1.35 + } 1.36 +} 1.37 + 1.38 /* main */ 1.39 int main(int argc, char* argv[]) { 1.40 unsigned char shell_return; 1.41 + /* 1.42 init(); 1.43 1.44 printTree(root); 1.45 @@ -194,6 +226,8 @@ 1.46 printTree(root); 1.47 1.48 delete(root); 1.49 + */ 1.50 1.51 + read_input("./input_addition"); 1.52 exit(shell_return); 1.53 }