I am new to ANSI C programming. I am currently learning how to manipulate files.
My question is if I open a file using the fopen function, and finish the program without using fclose, can the file be damaged or is there a pending process on the PC or simply nothing happens?
Thank you very much in advance.
The result is dependent on the Operating System.
When you acquire a resource (a file, a socket, ...) the system reserves that resource for you, offering you exclusive access to it. No one else will be able to access that resource while you have it reserved.
If the required access is read only, the system can provide shared access to the resource as long as all access is read.
If you acquire a resource but do not release it, the system maintains its reservation, so you prevent another application from accessing it.
What normally happens (at least in modern Operating Systems) is that when you close your application, the resources associated with said application are automatically freed... but it does not necessarily have to be that way. If it turns out that the resources are not released, they will be blocked indefinitely (because your application will no longer be able to release them by losing their identifiers) and the only solution will be to restart the computer.
Special care must be taken with remote resources, since then it is quite likely that the remote Operating System is not aware that your application has been closed, so the possibility of resources being blocked increases significantly.