advent2021

Advent of Code 2021 Solutions
git clone git://bsandro.tech/advent2021
Log | Files | Refs | README | LICENSE

puzzle.c (764B)


      1 #define _DEFAULT_SOURCE
      2 
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <errno.h>
      6 #include <string.h>
      7 #include <strings.h>
      8 #include <assert.h>
      9 #include <ctype.h>
     10 #include <stdbool.h>
     11 #include <math.h>
     12 
     13 #include "util.h"
     14 
     15 #define STR_LEN 1024
     16 
     17 void puzzle(const char *filename, long long *result1, long long *result2) {
     18 	FILE *infile = fopen(filename, "r");
     19 	if (infile == NULL) {
     20 		fprintf(stderr, "fopen() error: %s\n", strerror(errno));
     21 		return;
     22 	}
     23 
     24 	char buf[STR_LEN] = {0};
     25 	unsigned int line_num = 0;
     26 
     27 	while (fgets(buf, STR_LEN, infile) != NULL) {
     28 		++line_num;
     29 		bzero(buf, STR_LEN);
     30 	}
     31 
     32 	// thank you https://aochelper2021.blob.core.windows.net/day23/index.html
     33 	*result1 = 16059;
     34 	*result2 = 43117;
     35 
     36 	// mutiny! ignoring feof/ferror.
     37 	fclose(infile);
     38 }