Advent-of-Code/day1/solution-part1.c
Jonathan Hodgson f6a7e1dbfe Day 1
2021-12-01 22:03:50 +00:00

30 lines
519 B
C

#include <stdio.h>
int main( int argc, char *argv[] ){
if( argc == 2 ) {
unsigned int last = ~0;
unsigned int increasing = 0;
unsigned int value;
// Read the values into an array
FILE *fp=fopen(argv[1], "r");
while (!feof (fp)){
fscanf(fp, "%d\n", &value);
printf( "value %d\n", value );
if ( value > last )
increasing++;
last = value;
}
fclose(fp);
printf( "%d were increasing\n", increasing );
return 0;
} else {
printf("You need to provide a file\n");
return 1;
}
}