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 firstname.lastname@example.org. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Read/Write structure to a file in C
- Read/Write Class Objects from/to File in C++
- Input-output system calls in C | Create, Open, Close, Read, Write
- Read a record from a File in C++ using seekg() and tellg()
- Implement your own tail (Read last n lines of a huge file)
- How to write your own header file in C?
- fopen() for an existing file in write mode
- Write a C program that displays contents of a given file like 'more' utility in Linux
- C++ program to read file word by word
- C program to copy contents of one file to another file
- How to Read and Print an Integer value in C
- How to Read and Print an Integer value in C++
- Write a URL in a C++ program
- When should we write our own copy constructor?
- Write a C program that won't compile in C++
- When should we write our own assignment operator in C++?
- Write your own memcpy() and memmove()
- How to write a running C code without main()?
- C program to write an image in PGM format
- Write a program that produces different results in C and C++