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
klasskru [66]
1 year ago
5

Write a c program that reprints input so that no line is longer than 50 characters. Specifically, for lines less than or equal t

o 50 characters, simply reprint the line. For lines greater than 50 characters, insert a newline at each 50-character interval.
Note: If the 51st character of a line in the input is a newline '\n', then you should not print it (to avoid unnatural double newlines in the text). Depending on your solution, you may not need extra code for this. So worry about this case last.

Tip: Write your own file with test input for the case where the 51st character is a newline. In the bottom-right corner of Vim, you can see the line and column number of your cursor and plan your 51-character input accordingly.

Furthermore, to give developers feedback on their programs for 50-character-displays, you decide to add additional functionality to your program by displaying the line numbers of all lines over 50 characters long and the total number of these offending lines.

For example:

learncli$ cat test0.txt
This line is under 50 characters long
This line is just over 50 characters long, you see?
This line is soooooooooooooooooo looooouoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong!

learncli$ cat test0.txt | ./a.out
This line is under 50 characters long
This line is just over 50 characters long, you see
?
This line is soooooooooooooooooo looooouoooooooooo
oooooooooooooooooooooooooooooooooooooooooooooooooo
oooooong!

Total lines over 50 chars: 2
Offending lines: 1, 2,
learncli$
Computers and Technology
1 answer:
Alex73 [517]1 year ago
4 0

Using the knowledge in computational language in C++ it is possible to write a code that reprints prints input so that no line is longer than 50 characters.

<h3>Writting the code:</h3>

<em>#include<stdio.h></em>

<em />

<em>int main(int argc, char** argv){</em>

<em>    //creating pointer to read a file</em>

<em>    FILE * fp;</em>

<em>    char * line = NULL;</em>

<em>    size_t len = 0;</em>

<em>    ssize_t read;</em>

<em>    int i=0;</em>

<em>    //opening a file</em>

<em>    fp = fopen(argv[1], "r");</em>

<em>    //handling the error condition</em>

<em>    if (fp == NULL){</em>

<em>        printf("File not found..!!");</em>

<em>        return 0;</em>

<em>    }</em>

<em>    int moreThan50 =0;</em>

<em>    //reading a file line by line</em>

<em>    while ((read = getline(&line, &len, fp)) != -1) {</em>

<em>        i = 0;</em>

<em>        if(read >= 50){</em>

<em>            moreThan50++;</em>

<em>        }</em>

<em>        while(i < read){</em>

<em>            if(line[i]!='\n'){</em>

<em>                if(i%50 == 0){</em>

<em>                    printf("\n%c",line[i]);</em>

<em>                }else{</em>

<em>                    printf("%c",line[i]);</em>

<em>                }</em>

<em>            }</em>

<em>            i++;</em>

<em>        }</em>

<em>    }</em>

<em>    printf("\nTotal lines over 50 chars: %d\n",moreThan50);</em>

<em>    printf("Offending Lines: ");</em>

<em>    for(i=1;i<=moreThan50;i++)</em>

<em>        printf("%d, ",i);</em>

<em>    fclose(fp);</em>

<em>    return 0;</em>

<em>}</em>

See more about C++ at brainly.com/question/19705654

#SPJ1

You might be interested in
The incompatibilities in speed between the various devices and the CPU make I/O synchronization difficult, especially if there a
Iteru [2.4K]

Answer:

In a buffer

Explanation:

We can define a buffer as a temporary holding area for data between the various devices and the CPU make I/O synchronization especially if there are multiple devices attempting to do I/O at the same time.

Items stored at the buffer helps to reduce the The incompatibilities in speed between the various devices and the CPU.

3 0
3 years ago
Write a Python function prime_generator that takes as argument positive integers s and e (where s
nika2105 [10]

Answer:

def prime_generator(s, e):

   for number in range(s, e+1):      

       if number > 1:

          for i in range(2, number):

              if (number % i) == 0:

                  break

          else:

               print(number)

   

prime_generator(6,17)

Explanation:

I believe you want to ask the prime numbers between s and e.

- Initialize a for loop that iterates from s to e

- Check if the number is greater than 1. If it is, go inside another for loop that iterates from 2 to that number. If the module of that number to any number in range (from 2 to that number) is equal to 0, this means the number is not a prime number. If the module is not equal to zero, then it is a prime number. Print the number

6 0
3 years ago
An operating system can be categorized according to: question 1 options:
9966 [12]

Answer:

An operating system can be categorized according to both the given options. Thus answer is option C

Explanation:

An operating system should support multiple logins. Because the login plays a major role and that is the need and mainly in the organization where one system will be shared by multiple users. Also, Operating system should perform multi-tasking. This efficiency is required so that the user completes the work very faster and he need not wait to go for the next task.

For example an operating system handles user’s task, background tasks, keep track of the status of the devices, allots output device to the requested user and so on.  

5 0
3 years ago
Read 2 more answers
Protocol 2 - Check for Errors
Lapatulllka [165]

Please note that the Problem to be solved from Protocol 1 is not provided hence the general answers. To construct and send, open a network environment a single multi-packet message, simply click "Add Packet" and then click "Send at Once".

<h3>How will the receiver know the order of the packets or if any are missing?</h3>

If the text or message sent does not make any reading sense, or if certain words are jumbled and out of place, then it is clear that something is wrong.

If the messages arrive in a coherent fashion, then the packet was fully received.

<h3>How will the receiver request missed packets and what will the sender do in response?</h3>

Where the users are familiar with the Transmission Control Protocol, lost packets can be detected when there is a timeout. Lost packets are referred to as Dropped packets.

Learn more about Packets at:
brainly.com/question/17777733

7 0
1 year ago
What are keyboard skills?<br><br> For test
Reptile [31]

Answer: Letter recognition

Fine motor skills

Isolated use of each finger

Bilateral coordination (using two hands together)

Eye-hand coordination

Explanation:

5 0
2 years ago
Read 2 more answers
Other questions:
  • Design a data structure to support the following two operations for a set S of inte- gers, which allows duplicate values: • INSE
    15·1 answer
  • Can you know what time someone retweeted
    5·1 answer
  • How many slides should a presentation include?
    11·2 answers
  • Application partitioning gives developers the opportunity to write application code that can later be placed on either a client
    7·1 answer
  • Can y’all help me with these questions ?
    5·1 answer
  • You’re creating a table for one of your slides, and need to make some modifications to your table structure. Which of the follow
    6·2 answers
  • .in the array based list implementation of the ADT what is the worst case time efficiency of the remove method?
    6·1 answer
  • __________ is a program that lets you share documents online with others.
    12·2 answers
  • Can you give an example of mail merge (letter) pls​​
    6·1 answer
  • What spreadsheet tool could be used to add together the numbers in a<br> selected group of cells?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!