Files In C:
- stdio.h header file is providing variables and function to work with files.
- File is a physical storage area.
- File is a collection of bytes.
- We can store alphabets, digits and symbols into file.
- Each symbol occupies 1 byte memory. Hence it called Collection of bytes.
FILE*:
- FILE is a pre-defined structure type variable.
- FILE* can points to any type of file.
- Once we make the pointer pointing to a file, then we can perform all FILE operations such as reading, writing, appending and so on.
Modes of Files:
- We can open file using any one of following modes depends on requirement.
- Basic File modes as follows.
Modes of Files:
- We can open file using any one of following modes depends on requirement.
- Basic File modes as follows.
Read mode(“r”) :
- Opens file in Read mode.
- If file is present, it opens and returns pointer to that file.
- If file is not present, it returns NULL pointer.
Write mode(“w”) :
- Opens file in Write mode.
- If file is present, it opens and removes the existing contents of File.
- If file is not present, it creates the new file with specified name.
Append mode(“a”) :
- Opens file in append mode.
- If file is present, it opens and places the cursor at the end of existing data to add the new contents.
- If file is not present, it creates the new file with specified name.