Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.44 KB | None | 0 0
  1. #include <wchar.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <locale.h>
  5. #include <wctype.h>
  6.  
  7. #define BASE_COUNT_STRUCTURE 20
  8. #define BASE_LENGHT_STR 20
  9. #define Current_symbol text->all_str[line]->str[i]
  10. #define BASE_WORD_COUNT 30
  11.  
  12.  
  13.  
  14. struct Sentence
  15. {
  16.     wchar_t* str;
  17.     int lenght;
  18. };
  19.  
  20. struct Text
  21. {
  22.     struct Sentence** all_str;
  23.     int lenght;
  24. };
  25.  
  26. struct Words
  27. {
  28.     wchar_t* str;
  29.     int count;
  30. };
  31.  
  32.  
  33. void more_memory_struct(struct Text *text, int *count_struct)
  34. {
  35.     int i = 0;
  36.     text->all_str=(struct Sentence**)realloc(text->all_str,(*count_struct+BASE_COUNT_STRUCTURE)*sizeof(struct Sentence*));
  37.     for (i=*count_struct;i<((*count_struct)+BASE_COUNT_STRUCTURE);i++)
  38.     {
  39.         text->all_str[i]=(struct Sentence*)malloc(sizeof(struct Sentence));
  40.     }
  41.     for (i=*count_struct;i<((*count_struct)+BASE_COUNT_STRUCTURE);i++)
  42.     {
  43.         (text->all_str[i])->str=(wchar_t*)malloc(BASE_LENGHT_STR*sizeof(wchar_t));
  44.     }
  45.     *count_struct+=BASE_COUNT_STRUCTURE;
  46. }
  47.  
  48.  
  49. void more_memory_sentence(struct Sentence *sentence,int* lenght_str)
  50. {
  51.     sentence->str=(wchar_t*)realloc(sentence->str,(*lenght_str+BASE_LENGHT_STR)*sizeof(wchar_t));
  52.     *lenght_str+=BASE_LENGHT_STR;
  53. }
  54.  
  55.  
  56. void find_repeating_sentence(struct Text *text)
  57. {
  58.     int i,j,g;
  59.     for (i=0;i<((text->lenght)-1);i++)
  60.     {
  61.         for (j=(i+1);j<(text->lenght);j++)
  62.         {
  63.             if (compare(text->all_str[i]->str,text->all_str[j]->str))
  64.             {
  65.                 delete_repeating_sentence(text, j);
  66.                 j--;
  67.             }
  68.         }
  69.     }
  70. }
  71.  
  72. void delete_repeating_sentence(struct Text *text, int num)
  73. {
  74.     int i;
  75.     free (text->all_str[num]);
  76.     for (i=num;i<(text->lenght)-1;i++)
  77.     {
  78.         text->all_str[i]=text->all_str[i+1];
  79.     }
  80.     text->all_str[text->lenght]= NULL;
  81.     text->lenght-=1;
  82. }
  83.  
  84.  
  85. int compare(wchar_t* str1,wchar_t* str2)
  86. {
  87.     int i;
  88.     if (wcslen(str1) != wcslen(str2))
  89.         return 0;
  90.     else
  91.     {
  92.         for (i=0;i<wcslen(str1);i++)
  93.             if (towlower(str1[i])!=towlower(str2[i]))
  94.                 return 0;
  95.     }
  96.     return 1;
  97. }
  98.  
  99. int input_text(struct Text *text, int* count_struct)
  100. {
  101.  
  102.     int i = 0;
  103.     int line = 0;
  104.     int current_lenght_str = 0;
  105.     int flag_first_symbol = 0;
  106.     int lenght_str=BASE_LENGHT_STR;
  107.     wchar_t symbol;
  108.     symbol=getwchar();
  109.     while (symbol!='\n')
  110.     {
  111.         if (symbol!=' ')
  112.             flag_first_symbol=1;
  113.         if (flag_first_symbol)
  114.         {
  115.             Current_symbol=symbol;
  116.             if (i==(lenght_str-1))
  117.                 more_memory_sentence(text->all_str[line],&lenght_str);
  118.             i+=1;
  119.             if (symbol=='.')
  120.             {
  121.                 Current_symbol='\0';
  122.                 text->all_str[line]->lenght=i;
  123.                 line+=1;
  124.                 i=0;
  125.                 lenght_str=BASE_LENGHT_STR;
  126.                 flag_first_symbol = 0;
  127.             }
  128.         }
  129.         symbol=getwchar();
  130.         if (line == *count_struct)
  131.             more_memory_struct(text, count_struct);
  132.  
  133.     }
  134.     text->lenght=line;
  135. }
  136.  
  137.  
  138. int main()
  139. {
  140.     int i;
  141.     setlocale(LC_CTYPE, "");
  142.     int count_struct = 0;
  143.     int count_words= 0;
  144.     struct Text text = {NULL, 0};
  145.     more_memory_struct(&text, &count_struct );
  146.     input_text(&text, &count_struct);
  147.     p=&text;
  148.     find_repeating_sentence(&text);
  149.     for (i=0; i<(text.lenght);i++)
  150.         wprintf(L"%ls", text.all_str[i]->str);
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement