int main (){ FILE *input; input = fopen("text.txt", "r"); char *str = strnew(); sentence_t *currSentence = sentence_create(); text_t *text = text_create(); while (1) { char c = fgetc(input); if (c == EOF || isspace(c) || c == ',' || c == '.' || c == '!' || c == '?' || c == ';') { if (strlen(str) != 0) { word_t *word = word_new(str); sentence_add(currSentence, word); free (str); word_free (word); str = strnew(); } } if (c == EOF || c == '.' || c == '!' || c == '?') { text_add (text, currSentence); sentence_free(currSentence); currSentence = sentence_create(); } if (c == EOF) break; if (isalpha(c)) { c = tolower(c); char *w = stradd(str, c); free (str); str = w; } } fclose (input); FILE *output; output = fopen("result.txt", "w"); input = fopen ("stopwords.txt", "r"); int stopCount, i; fscanf (input, "%d", &stopCount); for (i = 0; i < stopCount; i++) { char s[15]; fscanf (input, "%s", s); fprintf (output, "%s: %d\n", s, text_find (text, s)); } fclose (input); fclose (output); free (str); sentence_free(currSentence); text_free(text); return 0; }
void text_free(text_t * text) { for (int i = 0; i < list_getSize(text->sentences); i++) sentence_free(list_get(text->sentences, i)); list_free(text->sentences); free(text); }
int main() { FILE * input = file_new("input.txt","r"); FILE * output = file_new("output.txt","w"); char buffer[100000]; sentence_t * sentence; word_t * word; fread(buffer,1,100000,input); text_t * text = text_new(buffer); removeSymbols(buffer); text_divide(text); int sentences_count = text_getSentencesCount(text); for (int i = 0; i < sentences_count; i++) { sentence = text_getSentence(text,i); sentence_divide(sentence); int words_count = sentence_getWordsCount(sentence); if (words_count < 5) sentence_deleteSentence(sentence); else { for (int j = 0; j < words_count; j++) { word = sentence_getWords(sentence,j); if (word_getWord(word) != NULL) fprintf(output,"%s,",word_getWord(word)); } fprintf(output,"\n"); } } word_free(word); sentence_free(sentence); text_free(text); file_free(input); file_free(output); printf("DONE"); return 0; }
void sentence_list_free(sentence_list_t * self){ for (int i = 0; i < self->sentenceCount;i++){ sentence_free(self->sentences[i]); } free(self); }