Friday, 15 May 2015

linux - How to replace multiple blank lines with a single line in C language -


I want to squeeze several rows in a row. I have tried to apply my argument but there is something wrong.

  char * p; Linecount = 0; While (fgets (buffer, size (buffer), file)) // it will print the user input with the number P = buffer; If ('\ r' == * p || '\ n' == * p) {linecount ++; If (linecount & gt; 2) printf ("\ n"); } And {linecount = 0; Printf ("\ t% s", p); For example  
  should be an output   

for example

Actually, I am dedicated to a code for the cat -s command.

"itemprop =" text ">

In your block:

  if (linecount> 2) printf ("\ n");  

What you're doing is printing the blank rows of the third, fourth, ....

Line line = 1

like first blank linecount = 2

like the other blank I will reverse that argument

 < Code> if (linecount == 0) {linecount ++; Printf ("\ n"); }  

In this way, you will only print the first blank line in the list of new lines.


No comments:

Post a Comment