/* Count unique words */ int tally(const gchar* itext, int start, int end, int tallied_length, int remove_ids) { unsigned char c; unsigned char *word = bufp; int i; int blank = 0; unsigned char *text = (char*)itext; save_body_bits(itext, start, end); /* Remove all text before @ signs. These are most likely Message-IDs and just pollute the word table. */ if (remove_ids) { for (i = end-1; i >= start; i--) { if ((c = text[i]) == '@') { blank = 1; } else if (blank == 1) { if (c == '<' || c == ' ' || c == '\n') blank = 0; else text[i] = ' '; } } } if ((tallied_length + end - start) >= MAX_MESSAGE_SIZE) { fprintf(stderr, "Max message size reached.\n"); return 0; } for (i = start; i<end; i++) { if ((c = downcase[text[i]]) != 0) { *bufp++ = c; } else { if (word != bufp) { if (! word_ignore(word, bufp)) { *bufp++ = 0; count_word(word); } word = bufp; } } } if (word != bufp && ! word_ignore(word, bufp)) { *bufp++ = 0; count_word(word); } return end - start; }
char *my_malloc2(char *tab, char *str, int i, char word) { tab = malloc(sizeof(tab) * ((count_word(str + i, word) + 1))); if (tab == NULL) exit(0); return (tab); }
void get_text(void) { char *temp_line_1; char *temp_line_2; int i = 0, j = 0; char buff[MAX_LINE] = {}; FILE *bible = fopen("The_Holy_Bible.txt", "rb"); while (fgets(buff, MAX_LINE, bible)) { temp_line_1 = (char *)malloc(sizeof(char) * MAX_LINE); strcpy(temp_line_1, buff); source_text[i++] = temp_line_1; total_char += strlen(temp_line_1); temp_line_2 = (char *)malloc(sizeof(char) * MAX_LINE); strcpy(temp_line_2, buff); to_space(temp_line_2); count_word(temp_line_2); remove_space(temp_line_2); handled_text[j++] = temp_line_2; } total_line = j; }
int main(int ac, char **av) { char **tab; int i; int start; i = 0; if (ac != 2) write(1, "\n", 1); if (ac != 2) return (0); start = count_word(av[1]) - 1; if (start < 0) { write(1, "\n", 1); return (0); } tab = ft_strsplit(av[1]); while (start > 0) { ft_putstr(tab[start--]); ft_putstr(" "); } ft_putstr(tab[start]); ft_putstr("\n"); while (i < start) free(tab[i++]); free(tab); tab = NULL; return (0); }
int main(int argc, char* argv[]) { assert(count_word("") == 0); assert(count_word(" ") == 0); assert(count_word("it") == 1); assert(count_word("it ") == 1); assert(count_word("it is") == 2); assert(count_word("it is used to count words.") == 6); assert(count_word("it is used to count words. is it easy?") == 9); return 0; }
// this function reads text from file, devide it into lines, and then passes each line // into countWord() function void read_text(std::ifstream& rf, std::map<std::string,int>& w_c, const std::set<std::string>& e_w){ std::string line; // call CountWord for each line while (std::getline(rf,line)) {count_word(line, w_c, e_w);} }