Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct SentenceArray *getAllSentencesArrayNew(const char *str) {
- int numOfSen = 0;
- int startOfSen = 0;
- int bindex = 0;
- for (int i = 0; i < strlen(str); i++)
- {
- if (str[i] == ' ' )
- {
- do
- {
- i++;
- } while (!(isalpha(str[i])) && str[i] != '\0');
- startOfSen = i;
- break;
- }
- else
- break;
- }
- for (int i = 0; i < strlen(str); i++)
- {
- if ((str[i] == '.' || str[i] == '!' || str[i] == '?') && (str[i + 1] != '.' && str[i + 1] != '?' && str[i + 1] != '!'))
- {
- numOfSen++;
- }
- }
- struct SentenceArray * newSentArray = malloc(sizeof(struct SentenceArray));
- newSentArray->sentences = malloc(numOfSen * sizeof(struct Sentence));
- for (int i = 0; i < numOfSen; i++)
- {
- for (int j = startOfSen; j < strlen(str); j++)
- {
- if (str[j] == '.' || str[j] == '\0' || str[j] == '!' || str[j] == '?')
- {
- newSentArray->sentences[i].string[bindex] = str[j];
- newSentArray->sentences[i].string[bindex + 1] = '\0';
- newSentArray->sentences[i].indexOfStart = startOfSen;
- startOfSen = j + 2;
- bindex = 0;
- break;
- }
- else
- {
- newSentArray->sentences[i].string[bindex] = str[j];
- bindex++;
- }
- }
- }
- newSentArray->numOfSentences = numOfSen;
- return newSentArray;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement