We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C
- Functions
- Querying the Document
- Discussions
Querying the Document
Querying the Document
Sort by
recency
|
146 Discussions
|
Please Login in order to post a comment
The split() function splits a string into an array of strings according to the 'delim' char argument and it updates the int pointer 'count' to the length of the array of strings. I used this function to do splits: document -> paragraphs, paragraphs -> sentences, sentences -> words.
I hope the reader finds the comments useful.
Here is my solution:
char* kth_word_in_mth_sentence_of_nth_paragraph(char**** document, int k, int m, int n) { return document[n-1][m-1][k-1]; }
char** kth_sentence_in_mth_paragraph(char**** document, int k, int m) { return document[m-1][k-1]; }
char*** kth_paragraph(char**** document, int k) { return document[k-1]; }
char* get_word(char text,int beg,int end){ char answer; answer=calloc(end-beg+1, sizeof(char)); int i,idex=0; for(i=beg;i<=end;i++){ answer[idex++]=text[i]; }
}
char** get_sentences(char text,int beg,int end){ char* answer; int word_count=1; int i; for(i=beg;i<=end;i++){ if(text[i]==' ') word_count++; } answer=calloc(word_count, sizeof(char*)); int start=beg,idex=0; for(i=beg;i<=end;i++){ if(text[i]==' '){ answer[idex++]=get_word(text, start, i-1); start=i+1; } } answer[idex]=get_word(text, start, i-1); return answer; }
char*** get_paragraphs(char* text,int beg,int end){ char*** answer; int sentence_count=0; int i; for(i=beg;i<=end;i++){ if(text[i]=='.') sentence_count++; } answer=calloc(sentence_count, sizeof(char**)); int start=beg,idex=0; for(i=beg;i<=end;i++){ if(text[i]=='.'){ answer[idex++]=get_sentences(text, start, i-1); start=i+1; } } return answer; }
char**** get_document(char* text) { char**** answer; int paragraph_count=1; int i; for(i=0;i
Hehe
Normal solution