advent-of-code-2021/1/1-1.c

22 lines
468 B
C
Raw Normal View History

2021-12-01 23:53:22 +08:00
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
int main(int argc, char const *argv[])
{
FILE *p_file = fopen("input", "r");
char line[50];
2021-12-04 21:30:27 +08:00
unsigned int increases = 0;
unsigned int previous_depth = 0;
2021-12-01 23:53:22 +08:00
while (fgets(line, sizeof line, p_file) != NULL)
{
if (atoi(line) > previous_depth)
{
increases++;
}
previous_depth = atoi(line);
}
printf("%u\n", increases - 1);
return 0;
}