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
Ivahew [28]
2 years ago
12

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:
Total lines over 50 chars: 2
Offending lines: 1, 2, learncli$
Computers and Technology
1 answer:
Fed [463]2 years ago
5 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>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
Write some difference between the third and fourth generation of computer?​
Whitepunk [10]

Answer:

<em>third generation of computer are larger than fourth generation. they are slower than fourth generation. IC chips were used whereas in fourth generation microprocessor were used. fourth generation consumed less electricity than third generation.</em>

<h3>I HOPE THIS WILL HELP YOU IF NOT THEN SORRY</h3>

HAVE A GREAT DAY :)

4 0
3 years ago
Read 2 more answers
The McCumber Model is a cube with three faces; each face has three items. It is intended to cause us to think about three areas
bagirrra123 [75]

Answer:

The three faces are information states, security goals, countermeasures.

Explanation:

Each face has different subjects about Informatics security, we will start with:

Information States

Storage is how we save data, for example, USB or hard drive.

Transmission is how we transfer data.

Process is how we make operations with data.

Security goals

Confidentiality is not showing data to unauthorized people.

Integrity is not modified data accidentally.

Availability is access to data timely.

Countermeasures

Politics is saving data with rules.

Human factors is training people in Informatics security.

Technology is software or hardware for Informatics security.

8 0
4 years ago
What tool enables you to easily delete, add, or resize filesystems without regard to their physical locations on a hard disk?
frosja888 [35]

Answer:

Logical Volume Management Tool

Explanation:

With Logical Volume Management(LVM), administrators and even users are offered a more flexible approach of managing space in disk storage. LVM provides method for sharing space(volume) on large storage devices (such as hard disk) with such greater flexibility than conventional partitioning strategies to store data. With LVM, users can easily duplicate, delete, add, resize and even file systems without much information about their physical locations on the storage device.

<em>Hope this helps!</em>

7 0
3 years ago
What is the post condition of an expression or variable
Jet001 [13]

Answer:

The post condition is simply a statement expressing what work has been accomplished by the function. This work might involve reading or writing data, changing the values of variable parameters, or other actions.

8 0
4 years ago
If you could build any machine what would be and why
xxMikexx [17]

Answer:

Nvidia RTX

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Steffie wants to change the margins of a worksheet to Normal to align it better on a printed page. To do this, what can she do a
    5·1 answer
  • If I wanted to add code so that the costume of my sprite would change, what menu would I look under to find the "change costume"
    11·1 answer
  • The main difference between a lan, a man, and a wan is _____. the ability to connect to the internet the geographic area they co
    8·1 answer
  • The negotiation by the transport layer at the sender with the transport layer at the receiver to determine what size packets sho
    14·1 answer
  • Which type of element is , and what is the meaning of that element ?
    6·1 answer
  • Jasmine is writing a shopping app. She has created a variable to keep track of the number of items in the shopping cart. Everyti
    11·1 answer
  • Jane, a marketing manager for the Grocery SuperStore retail chain, fired up a computer program that gave her ready access to inf
    6·1 answer
  • Vegetable farming is a good source of income explain this statement<br>​
    5·1 answer
  • Type your response in the box. Imagine you purchased a new computer and you plan to install one operating system and a few appli
    10·2 answers
  • Business Rules constraints falls into two categories:
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!