diff --git a/07/solution.c b/07/solution.c index 323d35d..e7dff0d 100644 --- a/07/solution.c +++ b/07/solution.c @@ -55,19 +55,20 @@ int main(void) { char l[64]; entry *root = calloc(1, sizeof(entry)); root->isdir++; - entry *current; + entry *current = root; size_t S = 0, G = 0, required = 0; while (fgets(l, 64, stdin)) { l[strlen(l) - 1] = '\0'; if (l[0] == '$') { - if (l[2] == 'c') + if (l[2] == 'c') { if (l[5] == '/') current = root; else if (l[5] == '.') current = current->parent; else current = findent(current, 1, l + 5); + } } else if (l[0] == 'd') { if (!findent(current, 1, l + 4)) addent(current, 1, l + 4); @@ -89,11 +90,12 @@ int main(void) { current->n_entries--; current = (current->entries++)[0]; } else { - if (current->isdir) + if (current->isdir) { if (current->size < 100000) S += current->size; else if (current->size >= required && (current->size < G || !G)) G = current->size; + } current = current->parent; }