Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define MIN_CHARACTERS 10
- int main(void){
- int currchar, // current character being read
- currlinelen = 0; // length of the line being read
- int characters[MIN_CHARACTERS];
- while( ( currchar = getchar() ) != EOF){
- printf("%i\n", currlinelen);
- if(currlinelen >= MIN_CHARACTERS){ // if the minimum length is achieved, print everything until next line ('\n')
- for(int thischar = 0; thischar < MIN_CHARACTERS; ++thischar) // prints everything stored in buffer
- putchar(characters[thischar]);
- do{
- putchar(currchar);
- } while( ( currchar = getchar() ) != '\n'); // prints all next characters until a new line
- currlinelen = 0;
- }
- else{
- if(currchar == '\n'){ // if there's a new line and we the min length hasn't been achieved, reset everything
- currlinelen = 0;
- continue;
- }
- characters[currlinelen] = currchar; // stores current character in the array
- ++currlinelen;
- }
- }
- }
Add Comment
Please, Sign In to add comment