void play_word_game(void) { char word_list[TOTAL_COUNT][MAX_WORD] = {""}; char read_word[MAX_WORD] = ""; char working_word[MAX_WORD] = ""; char c; int word_count; int score = 0; int win_score; int find_flag; srand( (unsigned int) time(NULL)); printf("time...%d\n", (unsigned int)time(NULL)); word_count = read_word_list("wordlist.txt", word_list); while(1) { printf("Current Score is : %d \n", score); printf("Figure it out!!!...\n"); get_new_word(word_list, word_count, read_word); init_working_word(read_word, working_word); win_score = 100; while(1) { display_word(working_word); c = getch(); if(c==ESC) { return; } printf("%c\n", c); find_flag = find_word(c, read_word, working_word); if (is_word_complete(read_word, working_word)) { display_word(working_word); printf("Success !!! \n\n"); score += win_score; break; } if (find_flag == FALSE && win_score-5>=0) { win_score -=5; } } } }
foreign_t pl_read_word_list(term_t filepath_term) { size_t length; char* filename; if(PL_is_string(filepath_term)) return PL_warning("please input a valid string"); else printf("input term is a string\n"); PL_get_chars(filepath_term,&filename,CVT_ALL|BUF_DISCARDABLE); printf("reading the file for list of words %s\n",filename); if(read_word_list(filename)==0) PL_succeed; else PL_fail; }
int main(int argc, char** argv) { if (argc == 3) { const char* wordlist_filename = argv[1]; const char* dawg_filename = argv[2]; EDGE_ARRAY dawg; inT32 max_num_edges = 100000000; inT32 reserved_edges = 1000000; dawg = (EDGE_ARRAY) Emalloc(sizeof (EDGE_RECORD) * max_num_edges); if (dawg == NULL) { printf("error: Could not allocate enough memory for DAWG "); printf("(%d ,%d bytes needed)\n", static_cast<int>(sizeof (EDGE_RECORD) * max_num_edges / 1000), static_cast<int>(sizeof (EDGE_RECORD) * max_num_edges % 1000)); exit(1); } printf("Building DAWG from word list in file, '%s'\n", wordlist_filename); read_word_list(wordlist_filename, dawg, max_num_edges, reserved_edges); trie_to_dawg(dawg, max_num_edges, reserved_edges); printf("Writing squished DAWG file, '%s'\n", dawg_filename); write_squished_dawg(dawg_filename, dawg, max_num_edges, reserved_edges); return 0; } else if (argc == 4 && strcmp(argv[1], "-t") == 0) { EDGE_ARRAY words = read_squished_dawg(argv[3]); check_for_words(words, argv[2]); memfree(words); return 0; } printf("Usage: %s [-t] word_list_file dawg_file\n", argv[0]); return 1; }
int treat_options( int argc, char *argv[] ) { char opt; int o_ptr; struct option longopts[] = { {"score", required_argument, 0, 's'}, {"targets", required_argument, 0, 't'}, {"neighbors", required_argument, 0, 'n'}, {"contexts", required_argument, 0, 'c'}, {"sim-threshold", required_argument, 0, 'S'}, {"dist-threshold", required_argument, 0, 'D'}, {"originals", no_argument, 0, 'o'}, {"threads", required_argument, 0, 'T'}, {"help", no_argument, 0, 'h'} }; char *shortopts = "s:t:n:c:S:D:T:oh"; while ((opt = getopt_long (argc, argv, shortopts, longopts, &o_ptr)) != -1) { switch( opt ) { case 's' : strcpy( score_name, optarg ); break; case 't' : t_filter = read_word_list( optarg ); break; case 'n' : n_filter = read_word_list( optarg ); break; case 'c' : c_filter = read_word_list( optarg ); break; case 'S' : sim_thresh = parse_thresh_option( optarg, opt ); sim_thresh_def = TRUE; break; case 'D' : dist_thresh = parse_thresh_option( optarg, opt ); dist_thresh_def = TRUE; break; case 'T' : if( sscanf( optarg, "%d", &nb_threads ) != 1 || nb_threads < 1 ) { fprintf( stderr, "Option -T requires positive integer: %s\n", optarg); usage(); } break; case 'o' : fprintf( stderr, "Will output original pairs\n" ); print_originals = TRUE; break; case 'h' : usage(); break; default: fprintf( stderr, "Unrecognized option: %c\n", opt ); usage(); } if( sim_thresh_def && dist_thresh_def ) { perr( "ERROR: Only one of -D or -S can be specified!\n" ); usage(); } } return optind; }