Fixed segfault when no arguments given
This commit is contained in:
parent
5198405eb4
commit
f7b25ecb92
6 changed files with 5 additions and 10 deletions
3
input.c
3
input.c
|
@ -17,7 +17,6 @@
|
|||
#define STAGE_2_ARG_COUNT 5
|
||||
#define STAGE_3_ARG_COUNT 5
|
||||
#define STAGE_4_ARG_COUNT 5
|
||||
#define OPEN_FILE_ERROR "Error: Unable to open file %s\n"
|
||||
|
||||
enum stages getStage(char *stage) {
|
||||
if (strcmp(stage, "1") == 0){
|
||||
|
@ -95,7 +94,7 @@ int getExpectedArgs(enum stages stage) {
|
|||
FILE *safeFileOpen(FILE **f, char *fileName, char *mode) {
|
||||
*f = fopen(fileName, mode);
|
||||
if (*f == NULL) {
|
||||
fputs(OPEN_FILE_ERROR, stderr);
|
||||
fprintf(stderr, "Error: Unable to open file %s\n", fileName);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return *f;
|
||||
|
|
BIN
input.o
BIN
input.o
Binary file not shown.
12
main.c
12
main.c
|
@ -8,14 +8,7 @@
|
|||
* The polygon can be split using a pair of integers, which represent
|
||||
* the edge numbers that should be connected. This comes from stdin.
|
||||
*
|
||||
* To run the program type:
|
||||
* ./voronoi1 dataset_file polygon_file output_file < splits
|
||||
*
|
||||
* Options:
|
||||
* dataset_file required Path to the dataset file (CSV)
|
||||
* polygon_file required Path to the polygon file (txt)
|
||||
* output_file required Output solution file
|
||||
* splits optional Pairs of integers to split the edges
|
||||
* To see valid input arguments, run ./voronoi2
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -69,6 +62,9 @@
|
|||
|
||||
int main(int argc, char **argv) {
|
||||
/* Ensure input arguments are correct */
|
||||
if (argc == 1) {
|
||||
printArgError(STAGE_ERROR, "Incorrect usage.");
|
||||
}
|
||||
enum stages stage = getStage(argv[1]);
|
||||
int expectedArgs = getExpectedArgs(stage);
|
||||
if (expectedArgs != argc) {
|
||||
|
|
BIN
main.o
BIN
main.o
Binary file not shown.
BIN
voronoi1
BIN
voronoi1
Binary file not shown.
BIN
voronoi2
BIN
voronoi2
Binary file not shown.
Loading…
Reference in a new issue