fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define WORDSIZE 64
  6.  
  7. struct Word
  8. {
  9. char* text;
  10. struct Word* next;
  11. };
  12.  
  13. struct Word* to_create_the_element_of_the_node(char* buff);
  14. struct Word* to_change_the_node(struct Word* First);
  15. void to_print_the_node(struct Word* First);
  16. void to_free_the_memory(struct Word* First);
  17.  
  18. int main(int argc, char* argv[])
  19. {
  20. int symbol;
  21. int i;
  22. char buff[WORDSIZE];
  23. FILE* open;
  24. struct Word* Current;
  25. Current=NULL;
  26. struct Word* Previous;
  27. Previous=NULL;
  28. struct Word* First;
  29. First=NULL;
  30.  
  31. if(argc<2)
  32. {
  33. fprintf(stderr, "Text file is not stated as the second argument \n");
  34. exit(0);
  35. }
  36. if(argc>2)
  37. {
  38. fprintf(stderr, "Too much of arguments \n");
  39. exit(0);
  40. }
  41. if((open=fopen(argv[1], "r"))==NULL)
  42. {
  43. fprintf(stderr, "Can not open file for reading \n");
  44. exit(0);
  45. }
  46. for(i=0; symbol=(getc(open))!=EOF;)
  47. {
  48. if(symbol!='\n' && symbol!=' ' && symbol!='\t')
  49. {
  50. buff[i]=symbol;
  51. i++;
  52. }
  53. if(symbol=='\n' || symbol==' ' || symbol=='\t')
  54. {
  55. buff[i]=='\0';
  56. i=0;
  57. if(First==NULL)
  58. {
  59. First=to_create_the_element_of_the_node(buff);
  60. Current=First;
  61. }
  62. else
  63. {
  64. Previous=Current;
  65. Current=to_create_the_element_of_the_node(buff);
  66. Previous->next=Current;
  67. }
  68. }
  69. }
  70. to_change_the_node(First);
  71. to_print_the_node(First);
  72. for(Current=First; Current!=NULL; Current=Current->next)
  73. {
  74. printf("%s", Current->text);
  75. }
  76. to_free_the_memory(First);
  77. }
  78.  
  79. struct Word* to_create_the_element_of_the_node(char* buff)
  80. {
  81. struct Word* Element;
  82. Element=(struct Word*)malloc(sizeof(struct Word));
  83. Element->next=NULL;
  84. strcpy(Element->text,buff);
  85. return Element;
  86. }
  87.  
  88. struct Word* to_change_the_node(struct Word* First)
  89. {
  90. struct Word* Current;
  91. struct Word* Buffer;
  92. for(Current=First; Current!=NULL || strlen(Current->text)>=3; Current=Current->next)
  93. while(Current->next!=NULL)
  94. {
  95. if(strlen(Current->next->text)>=3)
  96. {
  97. Buffer=Current->next;
  98. Current->next=Current->next->next;
  99. free(Buffer);
  100. }
  101. else
  102. {
  103. Current=Current->next;
  104. }
  105. }
  106. return First;
  107. }
  108.  
  109. void to_print_the_node(struct Word* First)
  110. {
  111. struct Word* Current;
  112. for(Current=First; Current!=NULL; Current=Current->next)
  113. {
  114. printf("%s", Current->text);
  115. }
  116. }
  117.  
  118. void to_free_the_memory(struct Word* First)
  119. {
  120. struct Word* Current;
  121. for(Current=First; Current!=NULL; Current=Current->next)
  122. {
  123. free(Current);
  124. }
  125. }
  126.  
  127.  
Success #stdin #stdout #stderr 0s 2164KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Text file is not stated as the second argument