Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Read text from a text file */
- void read_text(char word_array[][MAX_WORD_LEN], char * pointer_array[][2]) {
- int j, word_count = 0, pointer_count = 0, k, same_word_found, EOF_check;
- char word[MAX_WORD_LEN];
- do {
- EOF_check = scanf("%s", word);
- if (EOF_check == EOF) {
- break;
- }
- j = 0;
- /* Convert word to lowercase */
- while (word[j] != '\0') {
- word[j] = tolower(word[j]);
- j++;
- }
- same_word_found = 0;
- /* Compare currently read word with every word in the array */
- /* If found in array, set pointer to the memory address of the word in the array */
- for (k = 0; k < word_count; k++) {
- if (!(strcmp(word, & word_array[k][0]))) {
- pointer_array[pointer_count][0] = & word_array[k][0];
- pointer_count++;
- same_word_found = 1;
- break;
- } else {
- continue;
- }
- }
- /* If not found, add word to array and set pointer to memory address of newly added word */
- if (!same_word_found) {
- strcpy( & word_array[word_count][0], word);
- pointer_array[pointer_count][0] = & word_array[word_count][0];
- pointer_count++;
- word_count++;
- }
- } while (pointer_count < MAX_WORDS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement