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]
2 years 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]2 years 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
Which of the following is NOT part of the Ethernet standards? O 1.802.3 O 2.802.2 O 3 LLC O4 pPp
mote1985 [20]

Answer: 2) 802.2

Explanation: Ethernet standard are the standard for the networking technology for the transmission of the data.The ethernet is requires for the node connection and then forming the framework for the transmission of information.There are several standards for Ethernet.

802.3 is Ethernet standard that works on 10 Mbps rate, PPP(point to point protocol) is the standard that connects the internet service provider using modem and LLC(logical link control) is a standard for 802 .There is no 802.2 standard present in the ethernet standard.Thus,the correct option is option(2).

7 0
3 years ago
What is hypertext? Whata search engine? What is IT?
Verizon [17]

Answer:

Hypertext is a text in a document which references some other link within the same page or another page.

Search engine is an information retrieval system from larger pool of resources.

IT is for information technology whereby with the help of systems and communication medium we are able to send, retrieve information from one place to another.

Explanation:

Some website page can contain hypertext which is a link to another page. These are simple text upon clicking it lands us to another page or a pop up activity.

Examples of search engine is google with which we can search and retrieve information from a large database servers.

IT governs the ways these information exchanges taking place between client and sender with help of systems(computers) and communicating medium(internet).

7 0
3 years ago
Read 2 more answers
The following program is run. Then the user click the "bottomButton TWO TIMES, What will be displayed in the console
Mashutka [201]

Answer:

10

Explanation:

3 0
3 years ago
Lawyers, accountants, and engineers are __________ resources of microsoft. (points : 2) informational non-revenue-producing mate
tester [92]
 <span>Lawyers, accountants, and engineers are human resources of Microsoft. </span>
7 0
3 years ago
Discuss file Management<br>With relevant examples.<br>in a Computer?​
Artyom0805 [142]

Answer:

File management is the process of administering a system that correctly handles digital data. Therefore, an effective file management system improves the overall function of a business workflow. It also organizes important data and provides a searchable database for quick retrieval

6 0
3 years ago
Other questions:
  • Use the drop-down menus to complete the statements about using section breaks in a document
    9·1 answer
  • To download a webpage, the web browser copies files and transfer them to your ____
    14·2 answers
  • Performance testing is only important for real-time or embedded systems. <br> A) TRUE<br> B) FALSE
    14·1 answer
  • what tool can a student use to make sure his or her work paper does not take credit for someone else's work ?
    5·1 answer
  • ________ is used to install and update software, backup, and restore mobile devices, wipe employer software and data from device
    8·1 answer
  • Write a Twitter class that sets the Twitter user first (who is to be followed) and lets the client add up to 5 followers, which
    10·1 answer
  • A(n) ____ string contacts the data source and establishes a connection with the database using the Data Source Configuration Wiz
    5·1 answer
  • There are many commercially made household linens found in the?
    7·1 answer
  • Estoy haciendo codificación en este momento es tan confuso y no estar en la escuela es más difícil
    11·2 answers
  • What are the steps to apply new layout to the slide. ( Write in easy way)​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!