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 1
- #define BASE_LENGHT_STR 3
- #define Current_symbol text->all_str[line]->str[i]
- struct Sentence
- {
- wchar_t* str;
- int lenght;
- };
- struct Text
- {
- struct Sentence** all_str;
- int lenght;
- };
- 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 delete_first_spaces(struct Text *text)
- {
- int line = 0;
- int i = 0;
- for (line=0;line<(text->lenght);line++)
- {
- while (Current_symbol==' ')
- {
- i++;
- }
- memmove(text->all_str[line]->str[0],Current_symbol,((text->all_str[line]->lenght)-i)*sizeof(wchar_t));
- }
- }
- void delete_reapeting_sentnetce(struct Text *text)
- {
- int i,j;
- for (i=0;i<((text->lenght)-1);i++)
- {
- for (j=i;j<(text->lenght);j++)
- {
- if (compare(text->all_str[i],text->all_str[j]))
- {
- free (text->all_str[j]);
- free (text->all_str[j]);
- memmove(text->all_str[j],text->all_str[j+1],((text->lenght)-j)*sizeof(struct Sentence*));
- text->lenght-=1;
- }
- }
- }
- }
- int compare(const wchar_t* str1, const wchar_t* str2)
- {
- int i;
- if (wcslen(str1) == wcslen(str1))
- for (i=0;i<wcslen(str1);i++)
- if (towlower(str1[i])!=towlower(str2[i]))
- return 0;
- else
- 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()
- {
- setlocale(LC_CTYPE, "");
- int count_struct = 0;
- struct Text text = {NULL, 0};
- more_memory_struct(&text, &count_struct );
- input_text(&text, &count_struct);
- wprintf(L"%ls", text.all_str[0]->str);
- wprintf(L"%ls", text.all_str[1]->str);
- //wprintf(L"%ls", text.all_str[2]->str);
- // wprintf(L"%ls", text.all_str[3]->str);
- //wprintf(L"%ls", text.all_str[4]->str);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement