1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vladimir1956 [14]
3 years ago
6

See the lseek_example.c file. Modify the lseek_example.c, such that it reads from an input file (named "start.txt") and will pri

nt 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;
}
Computers and Technology
1 answer:
andre [41]3 years ago
3 0

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:

You might be interested in
What is the name for an object that is what it appears to be?
Gnesinka [82]
That would be a symbol
8 0
3 years ago
What happens to a mechanical system when two opposing torques do not cancel out?
const2013 [10]
The system will move in the direction of the stronger torque
5 0
3 years ago
what are the advantages of breaking up a single logical message into a number of fixed-sized packets and then sending each one o
aleksklad [387]

Explanation:

These are the advantages of breaking up a single logical message into a number of fixed sized packets.

- When messages are broken into packets it increases the performance and also the reliability of the internet

- if there is an error in a single packet, this error is not going to affect the entire message.

- the efficiency of the communication line in the internet is improved.

- there is a reduction of traffic. Each packet in a single message can be transmitted through different routes.

- It reduces idleness as each packet can send from different program so each program has a service.

8 0
2 years ago
1. Data in a smart card can be erased
Ostrovityanka [42]

Answer:

false

true

false

true

true

5 0
3 years ago
Read 2 more answers
Generally, websites ending in .edu, .gov, and .org are less likely to be biased, or to show preference toward a certain financia
svetlana [45]

Answer:

True

Explanation:

Domain extensions always appear at the end of a website's address.

It's a means to categorise websites.

.edu domains are used for educational purposes

.gov are restricted to by government entities

.org is largely used by nonprofit websites.

While

.net is derived from the word network, indicating it was originally intended for organizations involved in networking technologies, such as Internet service providers and other infrastructure companies

.biz is intended for registration of domains to be used by businesses

The right domain extension adds credibility and memorability to your website by aligning it with a specific brand purpose.

8 0
3 years ago
Other questions:
  • Annabella was giving a presentation to a group of 20 real estate agents on
    15·2 answers
  • DJ wants to see how his document will look when printed. Where would he find the button to see the document in print view? the P
    5·2 answers
  • In Excel, what happens to the cell contents when you click and drag a cell into multiple cells?
    14·1 answer
  • Computer virus is a<br> a. software<br> b. hardware<br> c. bacteria<br> d. none of these
    13·1 answer
  • "The _____ of the Open Systems Interconnection (OSI) model generates the receiver’s address and ensures the integrity of message
    6·2 answers
  • Where is the worlds biggest cookie​
    7·2 answers
  • What is the definition of software? Group of answer choices an instruction that causes a single specific action to be performed
    11·1 answer
  • What is "the last mile of broadband access"? Why is this a problem and what kind of impact does it have on the business world an
    9·1 answer
  • This morning when Paul turned on his computer at work, it would not boot. Instead, Paul reported that he heard a loud clicking n
    15·1 answer
  • What type of malware is best known for carrying other malware as a payload?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!