Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.74 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. void more_memory_words(struct Words *words, int *count_words)
  33. {
  34.     i=0;
  35.     words=(struct Words*)realloc(words,(*count_words+BASE_WORD_COUNT)*sizeof(struct Words));
  36.     *count_words=BASE_WORD_COUNT)
  37.     for (i=0;
  38. }
  39.  
  40. void more_memory_struct(struct Text *text, int *count_struct)
  41. {
  42.   int i = 0;
  43.     text->all_str=(struct Sentence**)realloc(text->all_str,(*count_struct+BASE_COUNT_STRUCTURE)*sizeof(struct Sentence*));
  44.     for (i=*count_struct;i<((*count_struct)+BASE_COUNT_STRUCTURE);i++)
  45.     {
  46.     text->all_str[i]=(struct Sentence*)malloc(sizeof(struct Sentence));
  47.     }
  48.     for (i=*count_struct;i<((*count_struct)+BASE_COUNT_STRUCTURE);i++)
  49.     {
  50.      (text->all_str[i])->str=(wchar_t*)malloc(BASE_LENGHT_STR*sizeof(wchar_t));
  51.     }
  52.     *count_struct+=BASE_COUNT_STRUCTURE;
  53. }
  54.  
  55.  
  56. void more_memory_sentence(struct Sentence *sentence,int* lenght_str)
  57. {
  58.     sentence->str=(wchar_t*)realloc(sentence->str,(*lenght_str+BASE_LENGHT_STR)*sizeof(wchar_t));
  59.     *lenght_str+=BASE_LENGHT_STR;
  60. }
  61.  
  62.  
  63. void find_repeating_sentence(struct Text *text)
  64. {
  65.     int i,j,g;
  66.     for (i=0;i<((text->lenght)-1);i++)
  67.     {  
  68.         for (j=(i+1);j<(text->lenght);j++)
  69.         {
  70.             if (compare(text->all_str[i]->str,text->all_str[j]->str))
  71.                 {
  72.                     delete_repeating_sentence(text, j);
  73.                     j--;
  74.                 }
  75.         }
  76.     }
  77. }
  78.  
  79. void delete_repeating_sentence(struct Text *text, int num)
  80. {
  81.     int i;
  82.     free (text->all_str[num]);
  83.     for (i=num;i<(text->lenght)-1;i++)
  84.     {
  85.         text->all_str[i]=text->all_str[i+1];
  86.     }
  87.     text->all_str[text->lenght]= NULL;
  88.     text->lenght-=1;
  89. }
  90.  
  91.  
  92. int compare(wchar_t* str1,wchar_t* str2)
  93. {
  94.     int i;
  95.     if (wcslen(str1) != wcslen(str2))
  96.     return 0;
  97.     else
  98.     {
  99.         for (i=0;i<wcslen(str1);i++)
  100.             if (towlower(str1[i])!=towlower(str2[i]))
  101.                 return 0;
  102.     }
  103.     return 1;
  104. }
  105.  
  106. int input_text(struct Text *text, int* count_struct)
  107. {
  108.    
  109.     int i = 0;
  110.     int line = 0;
  111.     int current_lenght_str = 0;
  112.     int flag_first_symbol = 0;
  113.     int lenght_str=BASE_LENGHT_STR;
  114.     wchar_t symbol;
  115.     symbol=getwchar();
  116.     while (symbol!='\n')
  117.     {
  118.         if (symbol!=' ')
  119.             flag_first_symbol=1;
  120.         if (flag_first_symbol)
  121.         {
  122.             Current_symbol=symbol;
  123.             if (i==(lenght_str-1))
  124.                 more_memory_sentence(text->all_str[line],&lenght_str);
  125.             i+=1;
  126.             if (symbol=='.')
  127.             {
  128.                 Current_symbol='\0';
  129.                 text->all_str[line]->lenght=i;
  130.                 line+=1;
  131.                 i=0;
  132.                 lenght_str=BASE_LENGHT_STR;
  133.                 flag_first_symbol = 0;
  134.             }
  135.         }
  136.             symbol=getwchar();
  137.             if (line == *count_struct)
  138.                 more_memory_struct(text, count_struct);
  139.        
  140.     }
  141.     text->lenght=line;
  142. }
  143.  
  144.  
  145. int main()
  146. {
  147.     int i;
  148.     setlocale(LC_CTYPE, "");
  149.     int count_struct = 0;
  150.     int count_words= 0;
  151.     struct Text text = {NULL, 0};
  152.     more_memory_struct(&text, &count_struct );
  153.     input_text(&text, &count_struct);
  154.     p=&text;
  155.     find_repeating_sentence(&text);
  156.     for (i=0; i<(text.lenght);i++)
  157.     wprintf(L"%ls", text.all_str[i]->str);
  158.    
  159.    
  160.     struct Words* words;
  161.    
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement