Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <wchar.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale.h>
- #include <wctype.h>
- #define BASE_COUNT_STRUCTURE 20
- #define BASE_LENGHT_STR 20
- #define Current_symbol text->all_str[line]->str[i]
- #define BASE_WORD_COUNT 30
- struct Sentence
- {
- wchar_t* str;
- int lenght;
- };
- struct Text
- {
- struct Sentence** all_str;
- int lenght;
- };
- struct Words
- {
- wchar_t* str;
- int count;
- };
- void more_memory_words(struct Words *words, int *count_words)
- {
- i=0;
- words=(struct Words*)realloc(words,(*count_words+BASE_WORD_COUNT)*sizeof(struct Words));
- *count_words=BASE_WORD_COUNT)
- for (i=0;
- }
- void more_memory_struct(struct Text *text, int *count_struct)
- {
- int i = 0;
- text->all_str=(struct Sentence**)realloc(text->all_str,(*count_struct+BASE_COUNT_STRUCTURE)*sizeof(struct Sentence*));
- for (i=*count_struct;i<((*count_struct)+BASE_COUNT_STRUCTURE);i++)
- {
- text->all_str[i]=(struct Sentence*)malloc(sizeof(struct Sentence));
- }
- for (i=*count_struct;i<((*count_struct)+BASE_COUNT_STRUCTURE);i++)
- {
- (text->all_str[i])->str=(wchar_t*)malloc(BASE_LENGHT_STR*sizeof(wchar_t));
- }
- *count_struct+=BASE_COUNT_STRUCTURE;
- }
- void more_memory_sentence(struct Sentence *sentence,int* lenght_str)
- {
- sentence->str=(wchar_t*)realloc(sentence->str,(*lenght_str+BASE_LENGHT_STR)*sizeof(wchar_t));
- *lenght_str+=BASE_LENGHT_STR;
- }
- void find_repeating_sentence(struct Text *text)
- {
- int i,j,g;
- for (i=0;i<((text->lenght)-1);i++)
- {
- for (j=(i+1);j<(text->lenght);j++)
- {
- if (compare(text->all_str[i]->str,text->all_str[j]->str))
- {
- delete_repeating_sentence(text, j);
- j--;
- }
- }
- }
- }
- void delete_repeating_sentence(struct Text *text, int num)
- {
- int i;
- free (text->all_str[num]);
- for (i=num;i<(text->lenght)-1;i++)
- {
- text->all_str[i]=text->all_str[i+1];
- }
- text->all_str[text->lenght]= NULL;
- text->lenght-=1;
- }
- int compare(wchar_t* str1,wchar_t* str2)
- {
- int i;
- if (wcslen(str1) != wcslen(str2))
- return 0;
- else
- {
- for (i=0;i<wcslen(str1);i++)
- if (towlower(str1[i])!=towlower(str2[i]))
- return 0;
- }
- return 1;
- }
- int input_text(struct Text *text, int* count_struct)
- {
- int i = 0;
- int line = 0;
- int current_lenght_str = 0;
- int flag_first_symbol = 0;
- int lenght_str=BASE_LENGHT_STR;
- wchar_t symbol;
- symbol=getwchar();
- while (symbol!='\n')
- {
- if (symbol!=' ')
- flag_first_symbol=1;
- if (flag_first_symbol)
- {
- Current_symbol=symbol;
- if (i==(lenght_str-1))
- more_memory_sentence(text->all_str[line],&lenght_str);
- i+=1;
- if (symbol=='.')
- {
- Current_symbol='\0';
- text->all_str[line]->lenght=i;
- line+=1;
- i=0;
- lenght_str=BASE_LENGHT_STR;
- flag_first_symbol = 0;
- }
- }
- symbol=getwchar();
- if (line == *count_struct)
- more_memory_struct(text, count_struct);
- }
- text->lenght=line;
- }
- int main()
- {
- int i;
- setlocale(LC_CTYPE, "");
- int count_struct = 0;
- int count_words= 0;
- struct Text text = {NULL, 0};
- more_memory_struct(&text, &count_struct );
- input_text(&text, &count_struct);
- p=&text;
- find_repeating_sentence(&text);
- for (i=0; i<(text.lenght);i++)
- wprintf(L"%ls", text.all_str[i]->str);
- struct Words* words;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement