Computers and Technology
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;
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 22:00, elijah1090
Technician a says engine assemblies can be mounted longitudinally in a chassis. technician b says engine assemblies can be mounted transversely in a chassis. who is correct?
Answers: 2
image
Computers and Technology, 25.06.2019 06:10, gabbypittman20
In your pest busters game, how does player 2 move the ship_2 object? a pressing the w and s keys b. pressing the up arrow and down arrow keys c. moving the mouse from side to side d. moving the mouse up and down select the best answer from the choices provided
Answers: 3
image
Computers and Technology, 25.06.2019 08:00, destineenikole175
Implement a document scanning function wordcountengine, which receives a string document and returns a list of all unique words in it and their number of occurrences, sorted by the number of occurrences in a descending order. if two or more words have the same count, they should be sorted according to their order in the original sentence. assume that all letters are in english alphabet. you function should be case-insensitive, so for instance, the words “perfect” and “perfect” should be considered the same word.
Answers: 1
image
Computers and Technology, 25.06.2019 08:10, yangyang718
Rom also called main memory or system memoryis used to stor the essential parts of the operating while the computer is running / true or false
Answers: 2
Do you know the correct answer?
See the lseek_example. c file. Modify the lseek_example. c, such that it reads from an input file (n...

Questions in other subjects: