Initializacia
This commit is contained in:
		
							parent
							
								
									ee9e324e9f
								
							
						
					
					
						commit
						cf685571c5
					
				| @ -13,21 +13,24 @@ struct tree { | |||||||
| 
 | 
 | ||||||
| struct tree* read_tree() { | struct tree* read_tree() { | ||||||
|     char buffer[SIZE]; |     char buffer[SIZE]; | ||||||
|     if (!fgets(buffer, SIZE, stdin)) { |  | ||||||
|         return NULL; |  | ||||||
|     } |  | ||||||
|     buffer[strcspn(buffer, "\n")] = 0;  |  | ||||||
|      |      | ||||||
|     if (buffer[0] == '\0') {   |     while (fgets(buffer, SIZE, stdin)) { | ||||||
|         return NULL; |         buffer[strcspn(buffer, "\n")] = 0;  | ||||||
|  |          | ||||||
|  |         if (buffer[0] == '\0') { | ||||||
|  |             continue;  | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         struct tree* node = calloc(1, sizeof(struct tree)); | ||||||
|  |         strncpy(node->value, buffer, SIZE - 1); | ||||||
|  |         return node; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     struct tree* node = calloc(1, sizeof(struct tree)); |     return NULL; | ||||||
|     strncpy(node->value, buffer, SIZE - 1); |  | ||||||
|     return node; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| struct tree* load_tree() { | struct tree* load_tree() { | ||||||
|     struct tree* node = read_tree(); |     struct tree* node = read_tree(); | ||||||
|     if (!node) { |     if (!node) { | ||||||
| @ -42,13 +45,6 @@ struct tree* load_tree() { | |||||||
|             destroy_tree(node); |             destroy_tree(node); | ||||||
|             return NULL; |             return NULL; | ||||||
|         } |         } | ||||||
|     } else {   |  | ||||||
|         struct tree* extra = read_tree();  |  | ||||||
|         if (extra) { |  | ||||||
|             free(extra);  |  | ||||||
|             destroy_tree(node); |  | ||||||
|             return NULL; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return node; |     return node; | ||||||
| @ -57,6 +53,7 @@ struct tree* load_tree() { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| void run_tree(struct tree* tree) { | void run_tree(struct tree* tree) { | ||||||
|     if (!tree) { |     if (!tree) { | ||||||
|         return; |         return; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user