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
your computer is running exceptionally slow. not only does it take the operating system a long time to start, but programs also
aliina [53]

You would want to check for any programs running in the background, as well as run a virus scan.

8 0
2 years ago
25% of 60 min<br> 20% of 60 min<br> 33%% of 60 min
Alexxx [7]
15
12
19.8 cool cool cool
7 0
2 years ago
3) How ash traditional technology and modern
Fynjy0 [20]

Answer:

While the developed world benefits from the modern explosion of technology, countries like Ethiopia continue to rely on their forefathers' methods for important daily tasks such as farming, cooling, and providing clean water. These activities are often physically challenging, time and energy intensive, and are often carried out by female family members in many such societies. Furthermore, they can damage the local ecology and climate, such as deforestation and soil erosion caused by the use of trees for firewood. Western technologies are often too complicated, expensive, unacceptable, and difficult to maintain in developing societies, so they are of little or no use in these situations.

4 0
2 years ago
If you’re the victim of cyber bullying behavior, besides contacting your teacher or the school, where else can you go to find in
RideAnS [48]

parents

childline

ceop

family

3 0
3 years ago
which type of encoding involves relating new information to existing knowledge that you already have stored in long-term memory?
rjkz [21]

A type of encoding that involves relating new information to existing knowledge that you already have stored in long-term memory is: Semantic encoding.

Encoding can be defined as a communication process in which the sender of a message transforms an information into an encrypted message, in the form of notable symbols that represent ideas or concepts.

Generally, a message that has been encoded by a sender requires a decoding action by the recipient, in order for the communication process to be complete.

Semantic encoding is a type of encoding which typically involves the relation of new information with respect to an existing knowledge that has been stored in long-term memory.

In conclusion, semantic encoding deals with the encoding of meaning from new information rather than perceptual characteristics such as the meaning of words in English language.

Read more: brainly.com/question/24113575

7 0
2 years ago
Other questions:
  • Which of the following translates packets so that the node can understand them once they enter through a port?
    8·2 answers
  • Which of the following characters at the beginning of a cell signifies to Excel that it should perform a calculation for the val
    13·1 answer
  • The vast amount of data collected from Internet searches, social media posts, customer transactions, military
    8·1 answer
  • How do you get free Wifi on your phone without paying
    6·1 answer
  • What are the functions of online gaming communities?
    12·1 answer
  • Most software packages have functions for generating _____ about columns of data, which include statistical summaries like contr
    7·1 answer
  • Using Visio, create a Local Area Network (LAN) consisting of 12 computers, a switch, and three printers. The switch should be in
    11·1 answer
  • Write a program to enter a number and test if it is greater than 45.6. If the number entered is greater than 45.6, the program n
    10·1 answer
  • What does brainliest do?
    8·2 answers
  • X = 10<br> y = 20<br> x &gt; y<br> print("if statement")<br> print("else statement")
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!