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.
Here's my solution for this problem :-
struct document get_document(char* text) {
int s=0,p=1,i,j,k,l,m;
for(i=0;text[i]!='\0';i++)
if(text[i]=='.')
++s;
else if(text[i]=='\n')
++p;
int wc[p][s];
int sc[p];
for(i=0;i
++j;
k=0;
}
}
Structuring the Document
You are viewing a single comment's thread. Return to all comments →
Here's my solution for this problem :- struct document get_document(char* text) { int s=0,p=1,i,j,k,l,m; for(i=0;text[i]!='\0';i++) if(text[i]=='.') ++s; else if(text[i]=='\n') ++p; int wc[p][s]; int sc[p]; for(i=0;i ++j; k=0; } }
struct document *doc=malloc(sizeof(struct document)); struct paragraph *para=malloc(p*sizeof(struct paragraph)); doc->paragraph_count=p; doc->data=para; for(int i=0;idata[i].sentence_count=sc[i]; doc->data[i].data=sentn; for(int j=0;jdata[i].data[j].word_count=wc[i][j]; doc->data[i].data[j].data=wrd; for(int k=0;kdata[i].data[j].data[k].data=malloc(50*sizeof(char)); } } j=0,k=0,l=0,m=0; for(i=0;i!=strlen(text);i++) { if(text[i]!='\n'&&text[i]!='.'&&text[i]!=' ') { doc->data[j].data[k].data[l].data[m]=text[i]; ++m; } if(text[i]==' ') { m=0; ++l; } else if(text[i]=='.') { l=0; m=0; ++k; } else if(text[i]=='\n') { ++j; k=0; l=0; m=0;
} } return *doc; }
struct word kth_word_in_mth_sentence_of_nth_paragraph(struct document Doc, int k, int m, int n) {return Doc.data[n-1].data[m-1].data[k-1];}
struct sentence kth_sentence_in_mth_paragraph(struct document Doc, int k, int m) {return Doc.data[m-1].data[k-1];}
struct paragraph kth_paragraph(struct document Doc, int k) {return Doc.data[k-1];}