When writing a program that performs an operation on a file, what two fileassociated names do you have to work with in your code?
When writing a program that performs an operation on a file, you have to work with the following two file-associated names in your code:
File Name:
open()
in Python or fopen()
in C/C++. For example:
file_name = "data.txt"
File Handle (or File Object):
open()
function to open a file. For example:
file_handle = open(file_name, "r") # Opening the file in read mode
In C/C++, the file handle is represented by a FILE*
pointer obtained from the fopen()
function. For example:
FILE* file_handle = fopen(file_name, "r"); // Opening the file in read mode
It's important to handle files properly, including checking for errors while opening or closing the file and ensuring the file is closed after finishing the operations to avoid resource leaks and data corruption.