diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..dfe7034 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,34 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe", + "cppStandard": "gnu++14", + "intelliSenseMode": "windows-gcc-x64" + }, + { + "name": "Linux", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "/usr/bin/gcc", + "cppStandard": "gnu++14", + "intelliSenseMode": "linux-gcc-x64", + "cStandard": "c17" + } + ], + "version": 4 +} diff --git a/output.txt b/output.txt new file mode 100644 index 0000000..e69de29 diff --git a/voronoi.c b/voronoi.c index 29a247b..ff16e13 100644 --- a/voronoi.c +++ b/voronoi.c @@ -1,11 +1,47 @@ +/* voronoi.c +* +* Created by Rory Healy (healyr@student.unimelb.edu.au) +* 12th August 2021 +* +*/ + #include +#include #include #include "voronoi.h" +#define OPEN_FILE_ERROR "Error: Unable to open file %s\n" +#define NUM_FILE_ERROR "Error: Incorrect number of inputs (3 required).\n" +#define MALLOC_ERROR "Error: Cannot allocate memory.\n" + int main(int argc, char **argv) { FILE *dataset = NULL, *polygonData = NULL, *output = NULL; checkInputArgs(argc, argv, &dataset, &polygonData, &output); + watchtower_t *watchtowers = (watchtower_t *) malloc(sizeof(watchtower_t)); + if (watchtowers == NULL) { + fputs(MALLOC_ERROR, stderr); + exit(EXIT_FAILURE); + } + + char *buffer; + size_t bufsize = 32; + size_t characters; + + buffer = (char *)malloc(bufsize * sizeof(char)); + if( buffer == NULL) + { + perror("Unable to allocate buffer"); + exit(1); + } + + printf("Type something: "); + characters = getline(&buffer,&bufsize,stdin); + printf("%zu characters were read.\n",characters); + printf("You typed: '%s'\n",buffer); + + // Cleaning up data + free(watchtowers); fclose(dataset); fclose(polygonData); fclose(output); @@ -14,29 +50,31 @@ int main(int argc, char **argv) { void checkInputArgs(int argc, char **argv, FILE **datasetFile, \ FILE **polygonFile, FILE **outputFile) { - char *openFileError = "Error: Unable to open file %s\n"; - char *numFilesError = "Error: Incorrect number of inputs (3 required).\n"; - if (argc != 4) { - fputs(numFilesError, stderr); + fputs(NUM_FILE_ERROR, stderr); exit(EXIT_FAILURE); } *datasetFile = fopen(argv[1], "r"); if (*datasetFile == NULL) { - fprintf(stderr, openFileError, argv[1]); + fprintf(stderr, OPEN_FILE_ERROR, argv[1]); exit(EXIT_FAILURE); } *polygonFile = fopen(argv[2], "r"); if (*polygonFile == NULL) { - fprintf(stderr, openFileError, argv[2]); + fprintf(stderr, OPEN_FILE_ERROR, argv[2]); exit(EXIT_FAILURE); } *outputFile = fopen(argv[3], "w"); if (*outputFile == NULL) { - fprintf(stderr, openFileError, argv[3]); + fprintf(stderr, OPEN_FILE_ERROR, argv[3]); exit(EXIT_FAILURE); } } + +void readWatchtowers(watchtower_t *watchtowers, FILE* datasetFile) { + int numTowers = 1; + +} diff --git a/voronoi.h b/voronoi.h index 2d45b10..ebee5ca 100644 --- a/voronoi.h +++ b/voronoi.h @@ -1,2 +1,12 @@ -void checkInputArgs(int argc, char **argv, FILE **datasetFile, \ -FILE **polygonFile, FILE **outputFile); +typedef struct { + char *id; + char *postcode; + char *manager; + int population; + double x; + double y; +} watchtower_t; + +void checkInputArgs(int argc, char **argv, FILE **datasetFile, \ +FILE **polygonFile, FILE **outputFile); +void readWatchtowers(watchtower_t *watchtowers, FILE* datasetFile); diff --git a/voronoi1 b/voronoi1 index 196cd80..a1ce316 100644 Binary files a/voronoi1 and b/voronoi1 differ