feat: day 2
This commit is contained in:
6
day_1.c
6
day_1.c
@@ -7,7 +7,7 @@
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int read_line(FILE *f, bool replace_letters);
|
||||
int find_digits(FILE *f, bool replace_letters);
|
||||
int solve(const char *fileName, bool replace_letters);
|
||||
|
||||
char *buffer;
|
||||
@@ -35,14 +35,14 @@ int solve(const char *fileName, bool replace_letters) {
|
||||
|
||||
int sum = 0;
|
||||
while(!feof(f)) {
|
||||
sum += read_line(f, replace_letters);
|
||||
sum += find_digits(f, replace_letters);
|
||||
}
|
||||
fclose(f);
|
||||
return sum;
|
||||
}
|
||||
|
||||
// Read all digits form the next line in a file
|
||||
int read_line(FILE *f, bool replace_letters) {
|
||||
int find_digits(FILE *f, bool replace_letters) {
|
||||
int first = -1, last = 10; // Use first=-1 to detect unset value and last=10 to return 0 (-10 + 10) when no values are set
|
||||
|
||||
// Read the entire line as a string
|
||||
|
||||
Reference in New Issue
Block a user