hey all
i am curious about why even we use fopen even we have file* to point the current file. i mean what does "opening file" mean" ? what is the real point at opening file ?
hey all
i am curious about why even we use fopen even we have file* to point the current file. i mean what does "opening file" mean" ? what is the real point at opening file ?
You mean as opposed to say writing uncontrollably to random sectors on the disk?
Like a lot of things, file systems follow a transactional model where you have begin/end, open/close or acquire/release.
The first step is to get the resource, which may fail because it doesn't exist, is already in use, or you don't have permission.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
not fully but partly i kinda understand so actually you are saying it is important to take memory from disk so fopen does this right ?
fopen returns a token (in this case, it's a FILE*), which grants you permission to do other file operations like fgets, fread etc.
It's your train ticket.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.