aoc/2015/day01/answer01.c
2024-07-05 19:55:39 -04:00

32 lines
570 B
C

#include <stdio.h>
#include <stdint.h>
#include <string.h>
int main() {
int32_t floor = 0;
FILE *file = fopen("input", "r");
if (file == NULL) {
perror("Error opening file.");
return 1;
}
char buffer[256];
while (fgets(buffer, sizeof(buffer), file) != NULL) {
uint16_t length = strlen(buffer);
for (uint16_t i = 0; i < length; i++) {
if (buffer[i] == '(') floor++;
else if(buffer[i] == ')') floor--;
}
}
if (ferror(file)) {
perror("Error reading from file.");
return 1;
}
fclose(file);
printf("floor: %i\n", floor);
return 0;
}