C program to read a range of bytes from file and print it to console
Given a file F, the task is to write C program to print any range of bytes from the given file and print it to a console.
- fopen(): Creation of a new file. The file is opened with attributes as “a” or “a+” or “w” or “w++”.
- fgetc(): Reading the characters from the file.
- fclose(): For closing a file.
- Initialize a file pointer, say File *fptr1.
- Initialize an array to store the bytes that will be read from the file.
- Open the file using the function fopen() as fptr1 = fopen(argv, “r”).
- Iterate a loop until the given file is read and stored, the characters are scanned in the variable, say C using the fgetc() function.
- Store each character C extracted in the above step, to a new string S and print that string using the printf() function.
- After completing the above steps, close the file using the fclose() function.
Below is the implementation of the above approach:
My Personal Notes arrow_drop_up