subject
Computers and Technology, 19.03.2021 18:00 val452

See the lseek_example. c file. Modify the lseek_example. c, such that it reads from an input file (named "start. txt") and will print to an output file (named "end. txt") every (1+3*i)th character, starting from the 1st character in the input file. In other words, it will print the 1st character, then skip 2 characters and print the 4th one, then skip 2 characters and print the 7th one, and so on. For instance, for input file:
ABCDEFGHIJKLM
It will output:
ADGJM
Iseek_example. c file contant:
// C program to read nth byte of a file and
// copy it to another file using lseek
#include
#include
#include
#include
void func(char arr[], int n)
{
// Open the file for READ only.
int f_read = open("start. txt", O_RDONLY);
// Open the file for WRITE and READ only.
int f_write = open("end. txt", O_WRONLY);
int count = 0;
while (read(f_read, arr, 1))
{
// to write the 1st byte of the input file in
// the output file
if (count < n)
{
// SEEK_CUR specifies that
// the offset provided is relative to the
// current file position
lseek (f_read, n, SEEK_CUR);
write (f_write, arr, 1);
count = n;
}
// After the nth byte (now taking the alternate
// nth byte)
else
{
count = (2*n);
lseek(f_read, count, SEEK_CUR);
write(f_write, arr, 1);
}
}
close(f_write);
close(f_read);
}
// Driver code
int main()
{
char arr[100];
int n;
n = 5;
// Calling for the function
func(arr, n);
return 0;
}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 02:00
Think about some of the most memorable and forgettable games ever created. they can be games that were discussed in this unit or otherwise. what are some of the consistent factors that made certain games memorable to you? what were some of the consistent factors that made certain games forgettable to you? why? explain.
Answers: 1
question
Computers and Technology, 22.06.2019 07:30
An endless cycle of creation and response on the internet is called
Answers: 1
question
Computers and Technology, 23.06.2019 22:30
Lakendra finished working on her monthly report. in looking it over, she saw that it had large blocks of white space. what steps could lakendra take to reduce the amount of white space?
Answers: 3
question
Computers and Technology, 23.06.2019 23:00
Computer programming is one type of what career
Answers: 1
You know the right answer?
See the lseek_example. c file. Modify the lseek_example. c, such that it reads from an input file (n...
Questions
question
History, 27.08.2019 20:10
Questions on the website: 13722359