Scenario Description:
Today, my colleague said, in the existing tool code, you cannot use fopen to open the file, and then walk through to assist. But in solving the problem, it has been assumed that the file path has a character escaping the problem, there is no thought to print out the current cannot get to the file handle error, whether the file path does not exist. So the first is to replace the/, the result is conceivable, there is no role. Then replace it with \ \ or not. There is no reason, always thought.
Go back and write the simplest test procedure alone, no problem. The question of Unicode encoding is also excluded. At this time began Baidu fopen failure reasons to get. At the beginning of the plan to use the GetLastError function, but not be able to determine whether it is dedicated to the Windows API, so continue Baidu following results:
fprintf (stderr, "%s \ n", Strerror (errno)); results have no effect
Here is a useful piece of information:
fopen internal low AH use the CreateFile function, so the fopen call fails, you can also use GetLastError to view the error code.
Solution:
To fail, call the GetLastError () function, get the value of DWORD to 32, then open the tool and select View error code: The process cannot access the file because another program is accessing the file.
Reflection: If it is a character escaping, it must be unable to open a nonexistent file, as long as the error code can be solved by obtaining the problem.
Cross-examine: can multiple programs open read-only at the same time?
Answer: Of course it is possible, for reading, is shared, for writing, is exclusive.
fopen Open File Failure reason analysis