Check if output file actually opened, closes #1

This commit is contained in:
Inex Code 2020-03-05 17:14:12 +03:00
parent b5904455de
commit 5b62521df0
1 changed files with 6 additions and 2 deletions

View File

@ -65,8 +65,12 @@ int main(int argc, char* argv[]) {
pos = strstr(pos, "777");
}
FILE* output_file = fopen(argv[2], "w");
fwrite(input_file -> contents, sizeof(char), input_file -> size_of_file, output_file);
fclose(output_file);
if (output_file == NULL) {
fprintf(stderr, "Error opening output file");
} else {
fwrite(input_file -> contents, sizeof(char), input_file -> size_of_file, output_file);
fclose(output_file);
}
close_file(input_file);
return 0;
}