daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 1
  8. #define BASE_LENGHT_STR 3
  9. #define Current_symbol text->all_str[line]->str[i]
  10.  
  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.  
  27. void more_memory_struct(struct Text *text, int *count_struct)
  28. {
  29.   int i = 0;
  30.     text->all_str=(struct Sentence**)realloc(text->all_str,(*count_struct+BASE_COUNT_STRUCTURE)*sizeof(struct Sentence*));
  31.     for (i=*count_struct;i<((*count_struct)+BASE_COUNT_STRUCTURE);i++)
  32.     {
  33.     text->all_str[i]=(struct Sentence*)malloc(sizeof(struct Sentence));
  34.     }
  35.     for (i=*count_struct;i<((*count_struct)+BASE_COUNT_STRUCTURE);i++)
  36.     {
  37.      (text->all_str[i])->str=(wchar_t*)malloc(BASE_LENGHT_STR*sizeof(wchar_t));
  38.     }
  39.     *count_struct+=BASE_COUNT_STRUCTURE;
  40. }
  41.  
  42.  
  43. void more_memory_sentence(struct Sentence *sentence,int* lenght_str)
  44. {
  45.     sentence->str=(wchar_t*)realloc(sentence->str,(*lenght_str+BASE_LENGHT_STR)*sizeof(wchar_t));
  46.     *lenght_str+=BASE_LENGHT_STR;
  47. }
  48.  
  49.  
  50. void delete_first_spaces(struct Text *text)
  51. {
  52.    
  53.     int line = 0;
  54.     int i = 0;
  55.     for (line=0;line<(text->lenght);line++)
  56.     {
  57.         while (Current_symbol==' ')
  58.         {
  59.             i++;
  60.         }
  61.         memmove(text->all_str[line]->str[0],Current_symbol,((text->all_str[line]->lenght)-i)*sizeof(wchar_t));
  62.     }
  63. }
  64.  
  65. void delete_reapeting_sentnetce(struct Text *text)
  66. {
  67.     int i,j;
  68.     for (i=0;i<((text->lenght)-1);i++)
  69.     {
  70.         for (j=i;j<(text->lenght);j++)
  71.         {
  72.             if (compare(text->all_str[i],text->all_str[j]))
  73.                 {
  74.                     free (text->all_str[j]);
  75.                     free (text->all_str[j]);
  76.                     memmove(text->all_str[j],text->all_str[j+1],((text->lenght)-j)*sizeof(struct Sentence*));
  77.                     text->lenght-=1;
  78.                 }
  79.         }
  80.     }
  81. }
  82.  
  83. int compare(const wchar_t* str1, const wchar_t* str2)
  84. {
  85.     int i;
  86.     if (wcslen(str1) == wcslen(str1))
  87.         for (i=0;i<wcslen(str1);i++)
  88.             if (towlower(str1[i])!=towlower(str2[i]))
  89.                 return 0;
  90.     else
  91.     return 0;
  92.     return 1;
  93. }
  94.  
  95. int input_text(struct Text *text, int* count_struct)
  96. {
  97.    
  98.     int i = 0;
  99.     int line = 0;
  100.     int current_lenght_str = 0;
  101.     int flag_first_symbol = 0;
  102.     int lenght_str=BASE_LENGHT_STR;
  103.     wchar_t symbol;
  104.     symbol=getwchar();
  105.     while (symbol!='\n')
  106.     {
  107.         if (symbol!=' ')
  108.             flag_first_symbol=1;
  109.         if (flag_first_symbol)
  110.         {
  111.             Current_symbol=symbol;
  112.             if (i==(lenght_str-1))
  113.                 more_memory_sentence(text->all_str[line],&lenght_str);
  114.             i+=1;
  115.             if (symbol=='.')
  116.             {
  117.                 Current_symbol='\0';
  118.                 text->all_str[line]->lenght=i;
  119.                 line+=1;
  120.                 i=0;
  121.                 lenght_str=BASE_LENGHT_STR;
  122.                 flag_first_symbol = 0;
  123.             }
  124.             symbol=getwchar();
  125.             if (line == *count_struct)
  126.                 more_memory_struct(text, count_struct);
  127.         }
  128.        
  129.     }
  130.     text->lenght=line;
  131. }
  132.  
  133.  
  134. int main()
  135. {
  136.     setlocale(LC_CTYPE, "");
  137.     int count_struct = 0;
  138.     struct Text text = {NULL, 0};
  139.     more_memory_struct(&text, &count_struct );
  140.     input_text(&text, &count_struct);
  141.     wprintf(L"%ls", text.all_str[0]->str);
  142.     wprintf(L"%ls", text.all_str[1]->str);
  143.     //wprintf(L"%ls", text.all_str[2]->str);
  144.    // wprintf(L"%ls", text.all_str[3]->str);
  145.     //wprintf(L"%ls", text.all_str[4]->str);
  146. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top