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
Privacy Group of answer choices must be respected if we are to function as complete, self-governing agents is an absolute value
ElenaW [278]
Privacy group in article 3 in constitution section 3 too
8 0
2 years ago
Please check my answer! (Java)
nlexa [21]

Correct, you're looking for an outer loop that loops from 0 to 15, and an inner loop from 0 to 50.

3 0
3 years ago
Select four programs that make up system software.Select four programs that make up system software.
Alenkasestr [34]

Operating system

Boot code

Device drivers

Utilities

5 0
2 years ago
A(n) ____ consists of a series of related instructions, organized for a common purpose, that tells the computer what tasks to pe
yarga [219]

Answer:

The correct answer is "Program".  

Explanation:

Program is the collection of statement or instruction which is developed for creating any software or any purpose. The program is implemented or executed by a computer to perform a particular task.The particular programmer always writes an instruction to develop a program.

Program are always organized for the common purpose, that specifies the computer what tasks to perform as well as how to perform that particular task for example if programmer develops a program of calculator then it should be only used for the calculation purpose.

7 0
3 years ago
Which of the following is a basic concept associated with Web 2.0? Select one: a. shift in user's role from the passive consumer
soldier1979 [14.2K]

Answer:

A: shift in user's role from the passive consumer of content to its creator

Explanation:

During the phase of Web 2.0, consumers evolved from just been highly informed and socially connected (in other words, they evolved from being just passive consumers) to a more engaged and empowered consumer. This implied that consumers could easily adapt to new technologies to meet individual needs and create an emotional bond with brands. They evolved from passive consumers to being the creators of what they wanted to meet their specific needs.

5 0
3 years ago
Other questions:
  • Write a function called ReverseLetters that takes an input phrase consisting of a single word and reverses the sequence of lette
    15·1 answer
  • Why is the protocol down, even though you issued the no shutdown command for interface vlan 99?
    5·2 answers
  • What software is typically used for larger systems?
    11·1 answer
  • Big Data often involves a form of distributed storage and processing using Hadoop and MapReduce.
    12·1 answer
  • Which of the following might indicate a source on the internet is NOT reliable?
    6·1 answer
  • Given coins of denominations (value) 1 = v1 &lt; v2&lt; … &lt; vn, we wish to make change for an amount A using as few coins as
    11·1 answer
  • Clarissa is a computer programming consultant. When a client states that they have an extremely complex programming task, which
    10·2 answers
  • _____moves the head to proper track
    13·2 answers
  • What will be the range of the random numbers generated by the following code snippet? rand() % 50 + 5;
    14·1 answer
  • The principle of ________ strongly suggests that programs should execute with the least amount of privileges needed to complete
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!