Question: Iseek ( ) - Syntax The lseek ( ) system call is used to change the position of the file offset ( or file pointer

Iseek()- Syntax
The lseek() system call is used to change the position of the file offset (or file pointer) within an open file. This file offset
determines where in the file the next read or write operation will start. By using lseek(), you can move the file pointer to
different positions within the file, allowing you to read or write data at specific locations.
Syntax : off_t lseek(int fd, off_t offset, int whence);
fd: The file descriptor of the open file. This is the integer value returned by the open() system call.
offset: The number of bytes by which the file pointer should be moved. This can be a positive or negative value depending
on the direction in which you want to move the pointer.
whence: This parameter specifies the reference point from which the offset is applied. It can have one of the following
values:
Examples:
lseek(fd,5, SEEK_SET) This shifts the file pointer 5 positions forward, starting from the beginning of the file.
lseek(fd,5, SEEK_CUR) This moves the file pointer 5 positions forward from its current location in the file.
lseek(fd,-5, SEEK_CUR) This shifts the file pointer 5 positions backward from its current position in the file.
lseek(fd,-5, SEEK_END) This moves the file pointer 5 positions backward from the end of the file
using thia concepts and give me the correct code for the below questions.
Q1. Write a program to print characters starting from 15th character
till the 20th character of file F1.txt into file F4.txt.
Q2. Write a program to print the last 5 characters of a file.
Q3. Write a program to read a number(n) from the user. Print the first
n characters from the file F1.txt.
Q4. Write a program to print the second half of a file.
Q5. Write program(s) to show the use of SEEK_SET, SEEK_CUR and
SEEK_END

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!