Advertisement
maxim_shlyahtin

text

Dec 13th, 2022
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. Text readText() {
  2.     int size = BUFF_SIZE;
  3.     int length = 0;
  4.     int nlcount = 0;
  5.     Sentence **text = malloc(size * sizeof(Sentence *));
  6.     Sentence *sentence;
  7.     do {
  8.         sentence = readSentence();
  9.         sentence->length != 1 ? fix_of_sentence(sentence) : sentence;
  10.         if (sentence->str[0] == L'\n') {
  11.             nlcount++;
  12.             free(sentence);
  13.         } else {
  14.             nlcount = 0;
  15.             text[length++] = sentence;
  16.             if (length == size - 2) {
  17.                 size += MEM_STEP;
  18.                 text = realloc(text, size * sizeof(wchar_t *));
  19.                 if (text == NULL) {
  20.                     for (int i = 0; i < length; i++) {
  21.                         free(text[i]->str);
  22.                         free(text[i]);
  23.                     }
  24.                     Text txt;
  25.                     txt.size = size;
  26.                     txt.text = NULL;
  27.                     txt.length = length;
  28.                     return txt;
  29.                 }
  30.             }
  31.         }
  32.     } while (nlcount < 2);
  33.     Text txt;
  34.     txt.size = size;
  35.     txt.text = text;
  36.     txt.length = length;
  37.     return txt;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement