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;
}

Answers

Answer 1

Answer:

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;

}

Explanation:


Related Questions

. Which of these perform real-world activities such as eating, sleeping, walking, and running in virtual worlds?

Answers

Answer:

all

Explanation:

Answer:

avatars

Explanation: I just took the test

Other Questions
WILL GIVE BRAINLILESTHow could the event at the Triangle Shirtwaist factory been prevented? Answer please, To Kill a Mockingbird (red squared question) The line y = 2x +k is a tangent to the curve x + 2xy + 20 = 0.a Find the possible values of k.b For each of these values of k, find the coordinates of the point of contactof the tangent with the curve. Hello, its simple, i just cant get it Write down two facts of advice that you can give to other learners who wouldwant to engage in a fundraising activity. Romantic poets often (5 points)argue with unromantic poetswrite about relationshipscompare real life to natureappreciate city life most A day with my grandparents I NEEED HELP PLEASE ANYONE!! With step by step answer He wants to wrap the present. How much wrapping paper does he need if its 1:00 in the afternoon and he wants to give it to her at 5:00pm? help ill give brainliest if you give a correct answer A 2.35-kg rock is released from rest at a height of 21.4 m. Ignore air resistance and determine (a) the kinetic energy at 21.4 m, (b) the gravitational potential energy at 21.4 m, (c) the total mechanical energy at 21.4 m, (d) the kinetic energy at 0 m, (e) the gravitational potential energy at 0 m, and (f) the total mechanical energy at 0 m. Norris bought a television for $899. If the tax is 5.5%, how much sales tax will he pay? on average how many toes does a human have? I think I have too many (not in a test, just wondering) Please please please help me with this!!! Fake answers will be reported Que hay en la casa worksheet what would happen if mushrooms were producers? in the book stepsister the glass slipper smashed into glittering pieces after What is 3x3/6 because I cant figure it out The total weight of 9 bags of potatoes is 36 kilograms. Each bag weighs the same amount. What is the weight, in grams, of each bag of potatoes? 4 grams 40 grams 400 grams 4,000 grams Someone help me ASAP !