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.
char*kth_word_in_mth_sentence_of_nth_paragraph(char****document,intk,intm,intn){returndocument[n-1][m-1][k-1];}char**kth_sentence_in_mth_paragraph(char****document,intk,intm){returndocument[m-1][k-1];}char***kth_paragraph(char****document,intk){returndocument[k-1];}char**split_string(char*text,chardelim){assert(text!=NULL);char**result=malloc(1*sizeof(char*));intsize=1;char*temp=strtok(text,&delim);*result=temp;while(temp!=NULL){size++;result=realloc(result,size*sizeof(char*));temp=strtok(NULL,&delim);result[size-1]=temp;}returnresult;}char****get_document(char*text){assert(text!=NULL);// split text by '\n' and count number of paragraphschar**paragraphs=split_string(text,'\n');intnpar=0;while(paragraphs[npar]!=NULL){npar++;}char****doc=malloc((npar+1)*sizeof(char***));// set last position to NULL for the user// to know when the array ends.doc[npar]=NULL;inti=0;while(paragraphs[i]!=NULL){// split sentences of paragraph by '.' and count number of sentenceschar**sentences=split_string(paragraphs[i],'.');intnsen=0;while(sentences[nsen]!=NULL){nsen++;}doc[i]=malloc((nsen+1)*sizeof(char**));// set last position to NULL for the user// to know when the array ends.doc[i][nsen]=NULL;intj=0;while(sentences[j]!=NULL){// remember that doc[0][0] means: paragraph #0,// sentence #0 and should act like a pointer to// the first element of an array of words (strings)// split string by ' ' and associate doc[i][j]// with the array of strings representing words// that is returned by split_string.doc[i][j]=split_string(sentences[j],' ');j++;}i++;}returndoc;}
Querying the Document
You are viewing a single comment's thread. Return to all comments →