completed part 2
This commit is contained in:
parent
165eda59f3
commit
445927fd11
@ -1,2 +1,5 @@
|
||||
compile:
|
||||
gcc initialprog.c -Werror=switch -o initialprog
|
||||
|
||||
run:
|
||||
./initialprog
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user