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, 21.06.2019 16:00
What does josh silverman name as the most important aspect of managing finances?
Answers: 2
question
Computers and Technology, 21.06.2019 23:10
Write a method that accepts a string object as an argument and returns the number of words it contains. for instance, if the argument is "four score and seven years ago", the method should return the number 6. demonstrate the method in a program that asks the user to input a string and then passes that string into the method, printing out whatever the method returns.
Answers: 3
question
Computers and Technology, 22.06.2019 13:00
Which part of the cpu accepts data?
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
Quick pl which one of the following is considered a peripheral? a software b mouse c usb connector d motherboard
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
Physics, 27.05.2021 21:00
question
Arts, 27.05.2021 21:00
question
English, 27.05.2021 21:00
question
Mathematics, 27.05.2021 21:00
Questions on the website: 13722361