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 : offt lseekint fd offt 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:
lseekfd SEEKSET This shifts the file pointer positions forward, starting from the beginning of the file.
lseekfd SEEKCUR This moves the file pointer positions forward from its current location in the file.
lseekfd SEEKCUR This shifts the file pointer positions backward from its current position in the file.
lseekfd SEEKEND This moves the file pointer positions backward from the end of the file
using thia concepts and give me the correct code for the below questions.
Q Write a program to print characters starting from th character
till the th character of file Ftxt into file Ftxt
Q Write a program to print the last characters of a file.
Q Write a program to read a numbern from the user. Print the first
n characters from the file Ftxt
Q Write a program to print the second half of a file.
Q Write programs to show the use of SEEKSET, SEEKCUR and
SEEKEND
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
