Skip to content

Commit

Permalink
don't segfault if no file is found geez
Browse files Browse the repository at this point in the history
  • Loading branch information
ifacodes committed Dec 17, 2020
1 parent 90550f4 commit 70945a6
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions 4/4.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

int main(int argc, char* args[]) {
FILE* file = fopen("input", "r");
if (!file) return 0;
size_t length = get_filesize(file);
char* input = calloc(length, sizeof(char));
fread(input, sizeof(char), length, file);
Expand Down
1 change: 1 addition & 0 deletions 4/4a.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

int main(int argc, char* args[]) {
FILE* file = fopen("input", "r");
if (!file) return 0;
size_t length = get_filesize(file);
char* input = calloc(length, sizeof(char));
fread(input, sizeof(char), length, file);
Expand Down
1 change: 1 addition & 0 deletions 5/5.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

int main(int argc, char* args[]) {
FILE* file = fopen("input", "r");
if (!file) return 0;
size_t length = get_filesize(file);
char* input = calloc(length, sizeof(char));
fread(input, sizeof(char), length, file);
Expand Down
1 change: 1 addition & 0 deletions 6/6a.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

int main(int argc, char* args[]) {
FILE* file = fopen("input", "r");
if (!file) return 0;
size_t length = get_filesize(file);
char* input = calloc(length, sizeof(char));
fread(input, sizeof(char), length, file);
Expand Down
1 change: 1 addition & 0 deletions 6/6b.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

int main(int argc, char* args[]) {
FILE* file = fopen("input", "r");
if (!file) return 0;
size_t length = get_filesize(file);
char* input = calloc(length, sizeof(char));
fread(input, sizeof(char), length, file);
Expand Down
1 change: 1 addition & 0 deletions 7/7.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ int part1() {

int main(int argc, char* args[]) {
FILE* file = fopen("input", "r");
if (!file) return 0;
size_t length = get_filesize(file);
char* input = calloc(length, sizeof(char));
fread(input, sizeof(char), length, file);
Expand Down
1 change: 1 addition & 0 deletions 8/8a.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void execute() {

int main(int argc, char* args[]) {
FILE* file = fopen("input", "r");
if (!file) return 0;
instructions = calloc(1, sizeof(char*));
// each line is max 8 char + null terminator
instructions[0] = calloc(9, sizeof(char));
Expand Down
1 change: 1 addition & 0 deletions 8/8b.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ int part2(char** program, int line_amount) {

int main(int argc, char* args[]) {
FILE* file = fopen("input", "r");
if (!file) return 0;
char** instructions = 0;
int32_t acc = 0;
int i_amount = 0;
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Advent of Code 2020

#### by Aoife Bradley

---

If you want to test it with your input, place it with your input in a file called "input" beside the executable of the day.

only tested on ubuntu 20.10

compiled with `gcc -g x.c -o ./x -msse4.2`

I tried to make each day with no leaks or memory issues.

lemme know if there are any issues with the code. :)

0 comments on commit 70945a6

Please sign in to comment.