I want to open a file for reading and writing if it exists, or if not, create it and open it for writing.
The following code
FILE *file = fopen(argv[file_position], "r+");
if (!file)
file = fopen(argv[file_position], "w");
causes the error file_name: Bad file descriptor.
What is the cause of the error and how to avoid it?