From a given file (e.g. input.txt) read the alternate nth byte and write it on another file with the help of “lseek”.
lseek (C System Call): lseek is a system call that is used to change the location of the read/write pointer of a file descriptor. The location can be set either in absolute or relative terms.
off_t lseek(int fildes, off_t offset, int whence);
int fildes : The file descriptor of the pointer that is going to be moved
off_t offset : The offset of the pointer (measured in bytes).
int whence : The method in which the offset is to be interpreted
(rela, absolute, etc.). Legal value r this variable are provided at the end.
return value : Returns the offset of the pointer (in bytes) from the
beginning of the file. If the return value is -1,
then there was an error moving the pointer.
This article is contributed by Kishlay Verma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Input-output system calls in C | Create, Open, Close, Read, Write
- Wait System Call in C
- dup() and dup2() Linux system call
- fseek() in C/C++ with example
- ftell() in C with example
- Buffer Overflow Attack with Example
- C program to demonstrate fork() and pipe()
- exec family of functions in C
- Socket Programming in C/C++
- Four File Handling Hacks which every C/C++ Programmer should know
- Implement your own tail (Read last n lines of a huge file)
- C Program to print numbers from 1 to N without using semicolon?
- C program to delete a file
- C Program to merge contents of two files into a third file
- What is the best way in C to convert a number to a string?