/* 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); return 0; } void checkInputArgs(int argc, char **argv, FILE **datasetFile, \ FILE **polygonFile, FILE **outputFile) { if (argc != 4) { fputs(NUM_FILE_ERROR, stderr); exit(EXIT_FAILURE); } *datasetFile = fopen(argv[1], "r"); if (*datasetFile == NULL) { fprintf(stderr, OPEN_FILE_ERROR, argv[1]); exit(EXIT_FAILURE); } *polygonFile = fopen(argv[2], "r"); if (*polygonFile == NULL) { fprintf(stderr, OPEN_FILE_ERROR, argv[2]); exit(EXIT_FAILURE); } *outputFile = fopen(argv[3], "w"); if (*outputFile == NULL) { fprintf(stderr, OPEN_FILE_ERROR, argv[3]); exit(EXIT_FAILURE); } } void readWatchtowers(watchtower_t *watchtowers, FILE* datasetFile) { int numTowers = 1; }