#include #include #include #include int main() { int32_t floor = 0; uint32_t pos = 0; FILE *file = fopen("input", "r"); if (file == NULL) { perror("Error opening file."); return 1; } char buffer[256]; bool breakout = false; while (fgets(buffer, sizeof(buffer), file) != NULL) { uint16_t length = strlen(buffer); if (breakout) break; for (uint16_t i = 0; i < length; i++) { if (buffer[i] == '(') { floor++; pos++; } else if (buffer[i] == ')') { floor--; pos++; } if (floor == -1) { breakout = true; break; } } } if (ferror(file)) { perror("Error reading form file."); return 1; } fclose(file); printf("position: %i\n", pos); return 0; }