示例#1
0
int main(void) {
    // create the wordlist dictionary
    Dictionary wordlist = create_Dictionary(strcmp_wrapper, free, do_nothing);
    StrQueue sq = file2StrQueue("wordlist.txt");
    while (sq_length(sq)) {
        char *word = sq_remove_front(sq);
        insert(wordlist, word, VALID);
    }
    destroy_StrQueue(sq);
    sq = NULL;
    
    Dictionary autocor = create_Dictionary(strcmp_wrapper, free, free);
    sq = file2StrQueue("autocorrect.txt");
    while (sq_length(sq)) {
        char *word = sq_remove_front(sq);
        char *val = sq_remove_front(sq);
        //printf("%s %s\n", word, val);
        insert(autocor, word, val);
    }
    destroy_StrQueue(sq);
    sq = NULL;
    
    sq = file2StrQueue(NULL);
    int flag = 0;
    while (sq_length(sq)) {
        
        char *word = sq_remove_front(sq);
        char *in_cor = lookup(autocor, word);
        //printf("%s\n", in_cor);
        if (not_word(word)) {
            printf("%s(unrecgonized)", word);
        } else if (in_list(wordlist, word)) {
            printf("%s", word);
        } else if (in_cor) {
            printf("%s(corrected)", in_cor);
        } else {
            printf("%s[not_in_list]", word);
        }
        flag++;
        // add a new line between every ten words
        if (flag - 10 == 0) {
            printf("\n");
            flag = 0;
        } else if (sq_length(sq)) {
            printf(" ");
        } else printf("\n");
        
        free(word);
    }
    
    
    
    // free memory
    destroy_StrQueue(sq);
    destroy_Dictionary(autocor);
    destroy_Dictionary(wordlist);
}
示例#2
0
int main (void){
    StrQueue c = create_StrQueue();
    sq_add_back(c,"test1\n");
    char* temp = sq_remove_front(c);
    printf("%s", temp);
    free (temp);
    destroy_StrQueue(c);
    // otuput:test1
}