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.
Structuring the Document
Structuring the Document
Sort by
recency
|
123 Discussions
|
Please Login in order to post a comment
.c
not the prettiest code i've ever written
for (int i = 0; i < len; i++) { free(*(arr + i)); } free(arr); }
char ** split(char * s, const char delim, int * count) { char ** split_s = NULL; char * part = NULL; unsigned int idx_split_s = 0; unsigned int idx_part = 0;
char c = '\0'; for (unsigned int i = 0; *(s + i) != '\0'; i++) { c = *(s + i);
}
// append last part to split_s if (idx_part != 0) { // mark the end of part string part = realloc(part, sizeof(char) * (idx_part + 1)); *(part + idx_part) = '\0';
}
*count = idx_split_s;
return split_s; }
struct document get_document(char* text) { int * paragraph_count = calloc(1, sizeof(int)); int * sentence_count = calloc(1, sizeof(int)); int * word_count = calloc(1, sizeof(int));
// split into paragraphs and store temporarily char ** paragraphs_temp = split(text, '\n', paragraph_count);
struct document document; document.paragraph_count = *paragraph_count; // allocate space for paragraphs in document document.data = malloc(*paragraph_count * sizeof(struct paragraph));
char * s = NULL; for (int i = 0; i < *paragraph_count; i++) { s = *(paragraphs_temp + i); // get current paragraph
} // end of paragraph_count loop
free_ptr_ptr(paragraphs_temp, *paragraph_count);
free(word_count); free(sentence_count); free(paragraph_count);
return document; }
struct word kth_word_in_mth_sentence_of_nth_paragraph(struct document Doc, int k, int m, int n) { // return ((((*(Doc.data + --n)).data + --m)).data + --k);
}
struct sentence kth_sentence_in_mth_paragraph(struct document Doc, int k, int m) { // return (((Doc.data + --m)).data + --k);
}
struct paragraph kth_paragraph(struct document Doc, int k) { return *(Doc.data + --k); }