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 displayed in the alert dialog box after the following code is executed? var items = 3; for (var i = 1; i &lt;= items; i+
LenKa [72]

Answer:

The factorial of 3=6

Explanation:

Following are the description of the given question

  • This is JavaScript code .Here items are the variable that are holding the integer value "3".
  • After that there is 2 loop are iterating one is outer and one inner loop.
  • When i=1 1<=3 the condition of outer loop is true  the control moves the inner loop .
  • In the inner loop there is variable result that is initialized by 1 Now checking the condition of inner loop j=i i.e j=1 1>=1 condition of inner loop is true it executed the statement inside the inner loop  so result =1 .Now we increment the value of i of the outer loop.
  • i=2 2<=3 the condition of outer loop is true  the control moves the inner loop .
  • In the inner loop there is variable result that is initialized by 1 Now checking the condition of inner loop j=i i.e j=2 2>=1 condition of inner loop is true it executed the statement inside the inner loop  so result =2 .Now we increment the value of i of the outer loop.
  • Now i=3 3<=3 the condition of outer loop is true  the control moves the inner loop .
  • In the inner loop there is variable result that is initialized by 1 Now checking the condition of inner loop j=i i.e j=3 3>=1 condition of inner loop is true it executed the statement inside the inner loop  so result =6 .Now we increment the value of i of the outer loop.
  • i=4 4<=3 the condition of outer loop is false  the control moves from  the outer loop.
  • It print The factorial of 3=6

4 0
3 years ago
A network administrator is implementing multifactor authentication for employees who travel and use company devices remotely by
devlian [24]

Answer:

A networking administrator is a multi-factor authentication for employees who use company devices by using a VPN. The level of authentication is 802.1X and OTP.

Explanation:

Network administration is the computer network and uses multiple computers. A company and organization uses multiple computers and need a network admin to connect with a different system. Network administrators depend upon the organization. Some duties of the network administration are split and clearly defined such as

Configure the network hardware, servers, and routers

Upgrade the computer networks

Troubleshooting network issues

Assigning the network models

Deploying the software

Managing the servers

Implementing the security and measure

Network administration requires technical competence and will benefit as a network administrator.

For the level of authentication 802.1, X and OTP are suitable for network administration.

5 0
4 years ago
Essay:
nirvana33 [79]

Answer:

1) There are three ingredients needed to access the Internet from a laptop or desktop computer: (1) an ISP, (2) a modem and (3) a Web browser.

2) yeah ofcourse social media ia a very helpful tool for people because it helps us connect with people all around the globe.It helps you clear you doubts for the perfect example is now.You know you are clearing your doubt here in brainly which can be considered as a social media.

8 0
2 years ago
Write a C program that counts the number of vowels in a word. The C program reads words from an input file and then stores in an
polet [3.4K]

Answer:

Explanation:

The following code is written in C and does what the question requires. It uses the input file reads it and outputs the number of vowels to the file called output.dat

#include <ctype.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int str_count_in_chars(char *start, char *end, char *chars) {

   int count = 0;

   for (; start != end; count += !!strchr(chars, *(start++)));

   return count;

}

void str_swap_in_chars(size_t str_len, char **str, char *chars) {

   for (int front = 0, back = str_len - 1; front < back; front++) {

       if (strchr(chars, (*str)[front])) {

           for (; !strchr(chars, (*str)[back]); back--);

           char tmp = (*str)[front];

           (*str)[front] = (*str)[back];

           (*str)[back--] = tmp;

       }

   }

}

char *file_to_str(FILE *fin) {

   int buf_len = 64;

   char buf[buf_len];

   char *str = malloc(buf_len);

   str[0] = '\0';

   for (int i = 1; fgets(buf, buf_len, fin); i++) {

       if (!(str = realloc(str, i * buf_len))) {

           fprintf(stderr, "%s:%d realloc failed\n", __FILE__, __LINE__);

           exit(1);

       }

       strcat(str, buf);

   }

   return str;

}

int main() {

   char *vowels = "aeiou";

   FILE *fin = fopen("input.dat", "r");

   FILE *fout = fopen("output.dat", "w");

   if (!fin || !fout) {

       fprintf(stderr, "%s:%d fopen failed\n", __FILE__, __LINE__);

       exit(1);

   }

   char *words = file_to_str(fin);

   fclose(fin);

   int words_len = strlen(words);

   for (int i = 0; i < words_len;) {

       if (isspace(words[i])) {

           fputc(words[i++], fout);

           continue;

       }

       int start = i;

       for (; i < words_len && !isspace(words[i]); i++);

       char *word = words + start;

       int word_len = i - start;

       int vowel_count = str_count_in_chars(word, words + i, vowels);

       if (vowel_count % 2 == 0) {

           str_swap_in_chars(word_len, &word, vowels);

       }

       fprintf(fout, "%.*s_%dvow", word_len, word, vowel_count);

   }

   fclose(fout);  

   free(words);

   return 0;

}

5 0
3 years ago
An antonym for the word “help” which may be found in a dictionary is a. Assist c. Hold b. Abandon d. None of these
Luba_88 [7]
I would have to say the answer is abondon
5 0
3 years ago
Read 2 more answers
Other questions:
  • Using the CPI to calculate the inflation rate​ _______________ the underlying inflation​ rate, and using the core inflation rate
    7·2 answers
  • Legal counsel has notified the information security manager of a legal matter that will require the preservation of electronic r
    8·1 answer
  • Which of the following situations best illustrates the process of authentication?a.A Web site sets users' passwords to expire ev
    7·1 answer
  • Which type of memory helps in reading as well as writing data?
    13·1 answer
  • What is the smallest colorable area on a display device
    10·1 answer
  • Can someone help me with my homework?
    7·1 answer
  • Authentication is a mechanism whereby unverified entities or supplicants who seek access to a resource provide a label by which
    12·1 answer
  • Could u help me on this u just have to compare how its alike please help ​
    5·2 answers
  • An intruder with malicious intent breaks into an office and steals a hard drive containing sensitive information about the compa
    12·1 answer
  • A brief contains an initial definition statement of the design aim and defines any constraints?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!