From 445927fd117e5be8a44ab1ed0b8156c40fbf5182 Mon Sep 17 00:00:00 2001 From: ThomasBallantine Date: Sat, 15 Feb 2025 17:03:15 +0000 Subject: [PATCH] completed part 2 --- 2015_day_1/Makefile | 3 +++ 2015_day_1/initialprog.c | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/2015_day_1/Makefile b/2015_day_1/Makefile index 32db095..0b6a06d 100644 --- a/2015_day_1/Makefile +++ b/2015_day_1/Makefile @@ -1,2 +1,5 @@ compile: gcc initialprog.c -Werror=switch -o initialprog + +run: + ./initialprog \ No newline at end of file diff --git a/2015_day_1/initialprog.c b/2015_day_1/initialprog.c index 4600633..10565cc 100644 --- a/2015_day_1/initialprog.c +++ b/2015_day_1/initialprog.c @@ -4,17 +4,17 @@ FILE *fptr; char line1[10000]; int floor_number; +int flag_a; +int char_zero_cross; enum states{ START, PROCESS, - END, } state; enum events{ START_LOOP, INCREMENT, DECREMENT, - STOP_LOOP, ERROR_EVENT }; @@ -37,12 +37,9 @@ void step_state(enum events event){ break; case DECREMENT: floor_number--; - break; - case STOP_LOOP: - state = END; - break; + break; case ERROR_EVENT: - printf("ERROR!"); + printf("ERROR!\n"); exit(1); break; default: @@ -55,6 +52,7 @@ void step_state(enum events event){ int main() { +flag_a = 0; floor_number = 0; fptr = fopen("2015_day_1_input.txt", "r"); if(fptr == NULL) { @@ -76,6 +74,10 @@ while (line1[i] != '\0'){ exit(1); } i++; + if (floor_number < 0 && flag_a == 0){ + printf("first zero-crossing is at position %lu\n", i); + flag_a = 1; + } } printf("\nThe Floor number is: %d\n\n", floor_number);