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
Write a method void Print(int LastNumber, int numbersPerLine) that receives two integers
marysya [2.9K]

Answer:

Code is in the attached screenshot.

Explanation:

Assumed it was written in Java based on your other question asked.

7 0
3 years ago
Witch of the following attributes of a website indicates a more reliable source for information
Arada [10]
The only one of those I would trust is the site ending with EDU I hope this helps you.
4 0
3 years ago
What is the best definition of a network?
Nataliya [291]

Answer:

like tv or wifi

Explanation:

6 0
2 years ago
Read 2 more answers
Caroline has been asked to find a standard to guide her company’s choices in implementing information security management system
koban [17]

Answer:

ISO 27002

Explanation:

The acronym ISO stand for The International Organization for Standardization. its a non governmental body that is responsible for setting standards guide internationally.

while NIST stand for National Institute of Standards and technology and it is also a body that is responsible for setting up standard guide in the US..

ISO 27002  is a standard code for implementing information security management systems. while  ISO 27017 is for cloud security.  NIST 800-12 is a general security and NIST 800-14 is for policy development. thus option A is correct.

Note :

All code preceded by ISO is from The International Organization for Standardization and are international standard. while those preceded by NIST is from National Institute of Standards and technology  and are not international standard.

7 0
3 years ago
The correct or acceptable way of communicating on the internet is known as
stepladder [879]
I want to say e-mail.

8 0
3 years ago
Other questions:
  • Jake is photographing his pet puppy. He wants to preview the image the camera will capture. What part of the camera that is insi
    6·2 answers
  • Sizing handles are used in Microsoft® Word® to _____.
    13·1 answer
  • To change the background color of a page, which tab would you use?
    15·2 answers
  • 50 pts DO NOT ANSWER FOR POINTS
    9·1 answer
  • While in slide show mode, if you are not careful you can close the application by clicking the x on the menu bar. question 38 op
    12·2 answers
  • What do developers do to support software products? explain to users which development process model was used to make the produc
    8·1 answer
  • Which of the following statements accurately describes linked data?
    5·1 answer
  • In 200 words or more, please describe the Cyber Security Enhancement Act. Include when it was implemented and what it's purpose
    12·1 answer
  • Nicotine us a dangerous chemical found in Cigarettes; it is accompanied by two other very harmful chemicals. These are
    15·1 answer
  • What two windows security updates do most organizations always patch?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!