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
|
124 Discussions
|
Please Login in order to post a comment
Here’s a concise answer with the C code for parsing a document into paragraphs, sentences, and words, and handling queries to retrieve specific parts of the document: for more info to solve problems like this visit our site.
include
include
include
define MAX_PARAGRAPHS 100
define MAX_SENTENCES 100
define MAX_WORDS 100
// Structure Definitions struct word { char* data; };
struct sentence { struct word* data; int word_count; };
struct paragraph { struct sentence* data; int sentence_count; };
struct document { struct paragraph* data; int paragraph_count; };
struct document Doc;
// Initialize document void initialize_document(int n) { Doc.paragraph_count = n; Doc.data = (struct paragraph*)malloc(n * sizeof(struct paragraph)); }
// Parse document text void parse_document(char* text) { char* para_text = strtok(text, "\n"); int para_index = 0;
}
// Query Functions void get_paragraph(int p) { for (int i = 0; i < Doc.data[p - 1].sentence_count; i++) { for (int j = 0; j < Doc.data[p - 1].data[i].word_count; j++) { printf("%s ", Doc.data[p - 1].data[i].data[j].data); } printf(". "); } printf("\n"); }
void get_sentence(int p, int s) { for (int i = 0; i < Doc.data[p - 1].data[s - 1].word_count; i++) { printf("%s ", Doc.data[p - 1].data[s - 1].data[i].data); } printf("\n"); }
void get_word(int p, int s, int w) { printf("%s\n", Doc.data[p - 1].data[s - 1].data[w - 1].data); }
// Main function to process input int main() { int n; scanf("%d\n", &n);
}
.c
not the prettiest code i've ever written