From 9a8665ed2688fedfaa296daeb0d401064f4c4c9e Mon Sep 17 00:00:00 2001 From: AnnaSnoeijs Date: Fri, 15 Aug 2025 19:35:55 +0200 Subject: [PATCH] Updated to be fully C99 compatible --- connect4.c | 12 +++++++++--- makefile | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/connect4.c b/connect4.c index 8b99b57..f4ccdcb 100644 --- a/connect4.c +++ b/connect4.c @@ -143,8 +143,14 @@ int main( playboard.rows = (rowsint_t)atoi(optarg); break; case 'o': - filename = strdup(optarg); - outputfile = fopen( filename, "w" ); + // filename = strdup(optarg); + filename = calloc( strlen( optarg ) + 1, sizeof(char) ); + if( filename != NULL ){ + strcpy( filename, optarg ); + outputfile = fopen( filename, "w" ); + }else{ + fprintf( stderr, "ERR: COULD NOT ALLOCATE FILENAME\n" ); + } break; } } @@ -185,7 +191,7 @@ int main( playboard.height = calloc( playboard.columns, sizeof(rowsint_t) ); playboard.column = calloc( playboard.columns, sizeof(column_t) ); if( playboard.height == NULL || playboard.column == NULL ){ - fprintf( stderr, "ERROR: COULD NOT ALLOCATE BOARD" ); + fprintf( stderr, "ERROR: COULD NOT ALLOCATE BOARD\n" ); return 1; } // Initialize wins struct if used diff --git a/makefile b/makefile index 5d16aaa..604f492 100644 --- a/makefile +++ b/makefile @@ -7,7 +7,7 @@ ARCH = native O = s # Flags for the compiler -FLAGS = -std=gnu99 +FLAGS = -std=c99 FLAGS += -O$(O) FLAGS += -march=$(ARCH) # Only override gcc default tuning if specified in make command line