summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--1/part1.c4
-rw-r--r--1/part2.c6
-rw-r--r--2/part1.c8
-rw-r--r--2/part2.c6
-rw-r--r--3/part1.c4
-rw-r--r--3/part2.c7
6 files changed, 17 insertions, 18 deletions
diff --git a/1/part1.c b/1/part1.c
index f4e5d43..62ef852 100644
--- a/1/part1.c
+++ b/1/part1.c
@@ -5,7 +5,7 @@
#define INPUT_LEN 200
-int repair(int * arr)
+int repair(const int * arr)
{
for (int i = 0; i < INPUT_LEN; i++) {
for (int j = 0; j < INPUT_LEN; j++) {
@@ -20,7 +20,7 @@ int repair(int * arr)
int main()
{
- FILE * file = fopen("input", "r");
+ FILE *file = fopen("input", "r");
char buffer[8] = { 0 };
int input[INPUT_LEN] = { 0 };
diff --git a/1/part2.c b/1/part2.c
index 3fb06a6..6efb387 100644
--- a/1/part2.c
+++ b/1/part2.c
@@ -5,7 +5,7 @@
#define INPUT_LEN 200
-int repair(int * arr)
+int repair(const int *arr)
{
for (int i = 0; i < INPUT_LEN; i++) {
for (int j = 0; j < INPUT_LEN; j++) {
@@ -22,7 +22,7 @@ int repair(int * arr)
int main()
{
- FILE * file = fopen("input", "r");
+ FILE *file = fopen("input", "r");
char buffer[8] = { 0 };
int input[INPUT_LEN] = { 0 };
@@ -31,7 +31,7 @@ int main()
input[i] = atoi(buffer);
}
- fclose(file)
+ fclose(file);
printf("%i", repair(input));
}
diff --git a/2/part1.c b/2/part1.c
index b7b2f44..3d53cba 100644
--- a/2/part1.c
+++ b/2/part1.c
@@ -3,13 +3,13 @@
#include <stdlib.h>
#include <string.h>
-bool is_valid_password(char * pass, char * policy)
+bool is_valid_password(char *pass, char *policy)
{
int min = atoi(policy);
- char * minP = strchr(policy, '-');
+ char *minP = strchr(policy, '-');
int max = atoi(++minP);
char c = *(strchr(minP, ' ') + 1);
- char * p = pass;
+ char *p = pass;
int occ = 0;
do {
if (*p == c) {
@@ -22,7 +22,7 @@ bool is_valid_password(char * pass, char * policy)
int main()
{
- FILE * file = fopen("input", "r");
+ FILE *file = fopen("input", "r");
char buffer[128] = { 0 };
int valid = 0;
while (fgets(buffer, 128, file)) {
diff --git a/2/part2.c b/2/part2.c
index b856529..b167fcf 100644
--- a/2/part2.c
+++ b/2/part2.c
@@ -3,10 +3,10 @@
#include <stdlib.h>
#include <string.h>
-bool is_valid_password(char * pass, char * policy)
+bool is_valid_password(char *pass, char *policy)
{
int pos1 = atoi(policy) - 1;
- char * minP = strchr(policy, '-');
+ char *minP = strchr(policy, '-');
int pos2 = atoi(++minP) - 1;
char c = *(strchr(minP, ' ') + 1);
@@ -15,7 +15,7 @@ bool is_valid_password(char * pass, char * policy)
int main()
{
- FILE * file = fopen("input", "r");
+ FILE *file = fopen("input", "r");
char buffer[128] = { 0 };
int valid = 0;
while (fgets(buffer, 128, file)) {
diff --git a/3/part1.c b/3/part1.c
index c71ce0a..b6d209a 100644
--- a/3/part1.c
+++ b/3/part1.c
@@ -5,9 +5,9 @@
#define INC_RIGHT 3
-int count_trees(const char * filename)
+int count_trees(const char *filename)
{
- FILE * file = fopen(filename, "r");
+ FILE *file = fopen(filename, "r");
// Include space for newline and string terminator
char buffer[64] = { 0 };
diff --git a/3/part2.c b/3/part2.c
index 8bcdcfd..9214c25 100644
--- a/3/part2.c
+++ b/3/part2.c
@@ -3,9 +3,9 @@
#include <stdlib.h>
#include <string.h>
-int count_trees(int inc_right, int inc_down, const char * filename)
+int count_trees(int inc_right, int inc_down, const char *filename)
{
- FILE * file = fopen(filename, "r");
+ FILE *file = fopen(filename, "r");
// Include space for newline and string terminator
char buffer[64] = { 0 };
@@ -17,8 +17,7 @@ int count_trees(int inc_right, int inc_down, const char * filename)
int pos = inc_right;
int hit = 0;
for (int i = 1; fgets(buffer, 64, file); i++) {
- if (inc_down != 1 && i % inc_down != 0)
- {
+ if (inc_down != 1 && i % inc_down != 0) {
continue;
}