Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. struct SentenceArray *getAllSentencesArrayNew(const char *str) {
  2.     int numOfSen = 0;
  3.     int startOfSen = 0;
  4.     int bindex = 0;
  5.     for (int i = 0; i < strlen(str); i++)
  6.     {
  7.         if (str[i] == ' ' )
  8.         {
  9.             do
  10.             {
  11.                 i++;
  12.             } while (!(isalpha(str[i])) && str[i] != '\0');
  13.             startOfSen = i;
  14.             break;
  15.         }
  16.         else
  17.             break;
  18.     }
  19.     for (int i = 0; i < strlen(str); i++)
  20.     {
  21.         if ((str[i] == '.' || str[i] == '!' || str[i] == '?') && (str[i + 1] != '.' && str[i + 1] != '?' && str[i + 1] != '!'))
  22.         {
  23.             numOfSen++;
  24.         }
  25.     }
  26.     struct SentenceArray * newSentArray = malloc(sizeof(struct SentenceArray));
  27.     newSentArray->sentences = malloc(numOfSen * sizeof(struct Sentence));
  28.     for (int i = 0; i < numOfSen; i++)
  29.     {
  30.         for (int j = startOfSen; j < strlen(str); j++)
  31.         {
  32.             if (str[j] == '.' || str[j] == '\0' || str[j] == '!' || str[j] == '?')
  33.             {
  34.                 newSentArray->sentences[i].string[bindex] = str[j];
  35.                 newSentArray->sentences[i].string[bindex + 1] = '\0';
  36.                 newSentArray->sentences[i].indexOfStart = startOfSen;
  37.                 startOfSen = j + 2;
  38.                 bindex = 0;
  39.                 break;
  40.             }
  41.             else
  42.             {
  43.                 newSentArray->sentences[i].string[bindex] = str[j];
  44.                 bindex++;
  45.             }
  46.         }
  47.     }
  48.     newSentArray->numOfSentences = numOfSen;
  49.     return newSentArray;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement