Guest User

Untitled

a guest
Dec 7th, 2019
41
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. #define MIN_CHARACTERS 10
  4.  
  5. int main(void){
  6.     int currchar, // current character being read
  7.         currlinelen = 0; // length of the line being read
  8.  
  9.     int characters[MIN_CHARACTERS];
  10.  
  11.     while( ( currchar = getchar() ) != EOF){
  12.         printf("%i\n", currlinelen);
  13.         if(currlinelen >= MIN_CHARACTERS){ // if the minimum length is achieved, print everything until next line ('\n')
  14.  
  15.             for(int thischar = 0; thischar < MIN_CHARACTERS; ++thischar) // prints everything stored in buffer
  16.                 putchar(characters[thischar]);
  17.            
  18.            
  19.             do{
  20.                 putchar(currchar);
  21.             } while( ( currchar = getchar() ) != '\n'); // prints all next characters until a new line
  22.            
  23.             currlinelen = 0;
  24.         }
  25.         else{
  26.             if(currchar == '\n'){ // if there's a new line and we the min length hasn't been achieved, reset everything
  27.                 currlinelen = 0;
  28.                 continue;
  29.             }
  30.            
  31.             characters[currlinelen] = currchar; // stores current character in the array
  32.             ++currlinelen;
  33.         }
  34.     }
  35. }
RAW Paste Data