Ah, I see the problem.
If the file does not exist, inpFile will be assigned to NULL on line 23. The debugger will break on line 28 when we pass a NULL FILE * into fgets. The moral of this story is do error checking. One kinda lazy way of doing this is to change inpFile assignment to:
Code:
FILE *inpFile = fopen(inpPath, "r");
if (!inpFile) {
fprintf(stderr, "could not open %s\n", inpPath);
return 1;
}
Of course, good error handling and program flow control requires lots of practice. This little fix gets the job done, but it's not very descriptive and it interrupts program flow. People spending more time writing command-line tools might look into things like the perror() function, the errno variable, and such.
The other moral of the story is learning how to recognize a crash when you see one. In this case the bug was the value of a variable was wrong. When the debugger stops on a line of code, first look at that line of code. Does it look right? If it does, then look at the value of every variable involved in that like. In this case you would notice inpFile had a suspicious value (0) and do more digging. Similarly, stepping through programs line by line and watching how the variables change can help find these kinds of things.