#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define WORDSIZE 64

struct Word
{
     char* text;
     struct Word* next;
};

struct Word* to_create_the_element_of_the_node(char* buff);
struct Word* to_change_the_node(struct Word* First);
void to_print_the_node(struct Word* First);
void to_free_the_memory(struct Word* First);

int main(int argc, char* argv[])
{
     int symbol;
     int i;
     char buff[WORDSIZE];
     FILE* open;
     struct Word* Current;
     Current=NULL;
     struct Word* Previous;
     Previous=NULL;
     struct Word* First;
     First=NULL;

     if(argc<2)
     {
          fprintf(stderr, "Text file is not stated as the second argument \n");
          exit(0);
     }
     if(argc>2)
     {
          fprintf(stderr, "Too much of arguments \n");
          exit(0);
     }
     if((open=fopen(argv[1], "r"))==NULL)
     {
          fprintf(stderr, "Can not open file for reading \n");
          exit(0);
     }
     for(i=0; symbol=(getc(open))!=EOF;)
     {
          if(symbol!='\n' && symbol!=' ' && symbol!='\t')
          {
               buff[i]=symbol;
               i++;
          }
          if(symbol=='\n' || symbol==' ' || symbol=='\t')
          {
               buff[i]=='\0';
               i=0;
               if(First==NULL)
               {
                    First=to_create_the_element_of_the_node(buff);
                    Current=First;
               }
               else
               {
                    Previous=Current;
                    Current=to_create_the_element_of_the_node(buff);
                    Previous->next=Current;
               }
          }
     }
     to_change_the_node(First);
     to_print_the_node(First);
     for(Current=First; Current!=NULL; Current=Current->next)
     {
          printf("%s", Current->text);
     }
     to_free_the_memory(First);
}
               
struct Word* to_create_the_element_of_the_node(char* buff)
{
     struct Word* Element;
     Element=(struct Word*)malloc(sizeof(struct Word));
     Element->next=NULL;
     strcpy(Element->text,buff);
     return Element;
}

struct Word* to_change_the_node(struct Word* First)
{
     struct Word* Current;
     struct Word* Buffer;
     for(Current=First; Current!=NULL || strlen(Current->text)>=3; Current=Current->next)
     while(Current->next!=NULL)
     {
          if(strlen(Current->next->text)>=3)
          {
                 Buffer=Current->next;
                 Current->next=Current->next->next;
                 free(Buffer);
          }
          else
          {
               Current=Current->next;
          }
     }
     return First;
}

void to_print_the_node(struct Word* First)
{
     struct Word* Current;
     for(Current=First; Current!=NULL; Current=Current->next)
     {
          printf("%s", Current->text);
     }
}

void to_free_the_memory(struct Word* First)
{
     struct Word* Current;
     for(Current=First; Current!=NULL; Current=Current->next)
     {
          free(Current);
     }
}

