int main(int argc, char *argv[]) { int retval = 0; /* if no params, use stdin */ if (argc == 1) { int counts[3]; word_count(stdin, counts); printf("\t%d\t%d\t%d\n", counts[0], counts[1], counts[2]); } else { int total_lines, total_words, total_chars, total_files; total_lines = total_words = total_chars = total_files = 0; for (int i = 1; i < argc; i++) { int counts[3]; FILE* f = fopen(argv[i], "r"); word_count(f, counts); total_lines += counts[0]; total_words += counts[1]; total_chars += counts[2]; total_files++; fclose(f); printf("\t%d\t%d\t%d\t%s\n", counts[0], counts[1], counts[2], argv[i]); } if (total_files > 1) { printf("\t%d\t%d\t%d\ttotal (%d)\n", total_lines, total_words, total_chars, total_files); } } return retval; }
void nick_completion(char dumb, char *dumber) { char *q, *line; int i = -1; char *nick = NULL, *tmp; q = line = m_strdup(¤t_screen->input_buffer[MIN_POS]); if (in_completion == STATE_NORMAL) { i = word_count(line); nick = extract_words(line, i - 1, i); } if (nick) line[strlen(line) - strlen(nick)] = 0; else *line = 0; if ((tmp = getchannick(input_lastmsg, nick && *nick ? nick : NULL))) { malloc_strcat(&q, tmp); set_input(q); update_input(UPDATE_ALL); malloc_strcpy(&input_lastmsg, tmp); in_completion = STATE_COMPLETE; } new_free(&q); new_free(&nick); }
int main(int argc,char **argv) { FILE *fp; huffman_tree *huff; char prefix_arr[1000],*prefix; prefix=prefix_arr; /*start to statistics the word count*/ fp=fopen("test.txt","r"); word_table=hash_create(HASH_TABLE); while(get_word(fp)!=EOF){ printf("-------%s--------\n",word); if(word[0]!='\0') word_count(word); } hash_print(word_table); /*start to generate the huffman code*/ huff=huffman_generate_code(word_table); print_huffman_tree(huff); printf("print the huffman code\n"); print_huffman_code(huff,""); /*start to write the huffman code into file*/ return 0; }
/* main: parse args, loop over FILES, count and print results */ int main(int argc, char *args[]) { int i = 1; int fd; struct ht ht = {0, 0, 0, 0, 0}; i += parse_opts(argc, args, &ht); ht.side = END; /* if no options specified, fallback to default */ set_default(&ht); while (args[i]) { fd = open(args[i], O_RDONLY); if (fd < 0) { fprintf(stderr, "File %s not found.\r\n", args[i]); i++; continue; } struct wc wc = {0, 0, 0}; word_count(fd, &wc); close(fd); fd = open(args[i], O_RDONLY); set_offset(&ht, &wc); ouroboros(fd, &ht); close(fd); i++; } exit(0); }
void make_argv(int *argc, char ***argv, const char *str) { const char *i; size_t size; int tmp; /* figure out argc */ *argc = word_count(str); /* initialize argv */ *argv = malloc(sizeof(char *) * (*argc + 1)); (*argv)[*argc] = NULL; /* populate argv */ i = str; tmp = 0; while (*i) { if (isspace(*i)) { i++; continue; } size = strcspn(i, WSPACE); (*argv)[tmp] = malloc(size + 1); strncpy((*argv)[tmp], i, size); (*argv)[tmp][size] = 0; i += size; tmp++; } }
size_t FrTextSpan::wordCountOriginal() const { char *words = originalText() ; size_t count = word_count(words) ; FrFree(words) ; return count ; }
int main() { test_19_3_6_for_char(); word_count(); test_19_3_6_for_wchar_t(); }
void DLL_EXPORT print(word_t * self, int check){ if(check) { for(int i = 0 ; i < word_count(self) ; i++) printf("%s " , word_get(self , i)); } }
size_t FrTextSpan::wordCountInitial() const { const FrObject *txt = getMetaData(init_text_tag) ; if (txt && txt->consp() && ((FrList*)txt)->first() && ((FrList*)txt)->first()->stringp()) txt = ((FrList*)txt)->first() ; const char *printed = FrPrintableName(txt) ; return printed ? word_count(printed) : wordCountOriginal() ; }
int main(int argc, char **argv) { if (argc < 2) { printf("Usage: word_count \"[test string]\"\n"); return 0; } printf("Number of words: %d\n",word_count(argv[1])); return 0; }
std::string * CMD_Maker::words() { std::string * out; out = new (std::nothrow) std::string[word_count()]; int wordStart = 0; int wordEnd = 0; int index = 0; for (int i = 0; i < current_cmd.length(); i++) { wordEnd++; if (current_cmd[i] == ' ' && current_cmd[i-1] != ' ') { out[index] = current_cmd.substr(wordStart,wordEnd-wordStart-1); wordStart = wordEnd; index++; } } if (index != word_count()) { out[word_count() - 1] = current_cmd.substr(wordStart, current_cmd.length() - wordStart); } return out; }
int main(int argc, char *argv[]) { /* You can modify this file as needed, for example to test different * files. If you run on command line, this function optionally reads * the filename from command line, if one is included. */ char *filename = "testi.txt"; if (argc > 1) { filename = argv[1]; } printf("Line count: %d\n", line_count(filename)); printf("Word count: %d\n", word_count(filename)); }
int process_quotes(char* s) { int len = strlen(s); char* result; /* allocate node */ struct node* new_node = (struct node*) malloc(sizeof(struct node)); if (new_node == NULL) return NULL; // heap exhausted //result = (char *quote) malloc(sizeof (char)* (len+1)); result->quote = (char *) malloc(len * sizeof char); strcpy(result->quote, node.quote->quote); if(result == NULL) return NULL; // heap exhausted result = word_count(s); new_node->count = result; new_node->quote = s; new_node->next = NULL; struct node* current; if((*head == NULL) || ((*head)->count >= new_node->count)) { new_node->next = *head; *head = new_node; } else { /* locate the node before insertion */ current = *head; while(current->next != NULL && current->next->count < new_node->count) { current = current->next; } new_node->next = current->next; current->next = new_node; } return 1; //success }
/* sent-im-msg */ static void sent_im_msg(PurpleAccount *account, const char *receiver, const char *message) { PurpleBuddy *buddy; guint interval, words; CapStatistics *stats = NULL; buddy = purple_find_buddy(account, receiver); if (buddy == NULL) return; interval = purple_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 60; words = word_count(message); stats = get_stats_for(buddy); insert_word_count(purple_account_get_username(account), receiver, words); stats->last_message = time(NULL); stats->last_message_status_id = purple_status_get_id(get_status_for(buddy)); if(stats->timeout_source_id != 0) purple_timeout_remove(stats->timeout_source_id); stats->timeout_source_id = purple_timeout_add_seconds(interval, max_message_difference_cb, stats); }
void FNeuralNetLMBase::TrainLM(const string &validationfile, const string &outbase, bool nce_ppl) { // ============= // Prepare for the training // Equivalent to ReadLM word_vocab_.ReadVocabFromTxt(word_vocab_filename_); if (word_vocab_.empty()) { cerr << "empty word vocabulary!" << endl; exit(EXIT_FAILURE); } factor_vocab_.ReadVocabFromTxt(factor_vocab_filename_); if (factor_vocab_.empty()) { cerr << "empty factor vocabulary!" << endl; exit(EXIT_FAILURE); } ReadDecompFromTxt(decomp_filename_); PrintParams(); CheckParams(); AllocateModel(); InitializeNeuralNet(); // ==== END ==== // Read the data FNNLMDataReader train_data(train_filenames_, &word_vocab_, &factor_vocab_, shuffle_datafiles_, shuffle_sentences_); vector<string> validation_filenames = { validationfile }; FNNLMDataReader validation_data(validation_filenames, &word_vocab_, &factor_vocab_, false, false); // Set NCE sampling. if (nce_) { // TODO: flatten noise_distribution_? vector<int> word_count(word_vocab_.size(), 0); int num_word_tokens = 0; const size_t eos_widx = word_vocab().eos_idx(); vector<int> factor_count(factor_vocab_.size(), 0); int num_factor_tokens = 0; const size_t eos_fidx = factor_vocab().eos_idx(); vector<pair<size_t, vector<size_t>>> sentence; train_data.StartEpoch(); while(train_data.GetSentence(sentence)) { for (vector<pair<size_t, vector<size_t>>>::const_iterator it = sentence.begin(); it != sentence.end(); ++it) { word_count[it->first]++; num_word_tokens++; if (weight_factor_output_ > 0) { for (size_t p = 0; p < it->second.size(); p++) { factor_count[it->second[p]]++; num_factor_tokens++; } } } word_count[eos_widx]++; num_word_tokens++; if (weight_factor_output_ > 0) { factor_count[eos_fidx]++; num_factor_tokens++; } } word_noise_distribution_ = Distribution(word_count.begin(), word_count.end()); word_noise_pdf_ = word_noise_distribution_.param().probabilities(); if (weight_factor_output_ > 0) { factor_noise_distribution_ = Distribution(factor_count.begin(), factor_count.end()); factor_noise_pdf_ = factor_noise_distribution_.param().probabilities(); } NCECheckSampling(); log_num_negative_samples_ = log(num_negative_samples_); } BatchSGDTrain(train_data, validation_data, outbase, nce_ppl); cout << "================================================================================" << endl; cout << "Log-likelihood (base e) on validation is: " \ << EvalLM(validation_data, false) << endl; }
size_t FrTextSpan::wordCount() const { return m_text ? word_count(m_text) : wordCountOriginal() ; }
void make_max_argv(int *argc, char ***argv, const char *str, size_t n) { const char *i; size_t size; int tmp; int add_extra; /* figure out argc */ *argc = word_count(str); if (*argc >= n) { *argc = n; } if (bool_option("verbose")) cio_out("argc = %d\n", *argc); /* initialize argv */ *argv = malloc(sizeof(char *) * (*argc + 1)); (*argv)[*argc] = NULL; /* populate argv */ i = str; tmp = 0; while (*i && tmp < n - 1) { add_extra = 0; if (isspace(*i)) { i++; continue; } if(*i == '"') { i++; size = strcspn(i, "\""); add_extra = 1; } else if (*i == '\'') { i++; size = strcspn(i, "'"); add_extra = 1; } else { size = strcspn(i, WSPACE); } (*argv)[tmp] = malloc(size + 1); strncpy((*argv)[tmp], i, size); (*argv)[tmp][size] = 0; if (bool_option("verbose")) cio_out("argv[%d] = \"%s\"\n", tmp, (*argv)[tmp]); i += size + add_extra; tmp++; } if (*argc != n) return; /* we are done here */ /* get the final entry to argv */ while (*i) { assert(tmp == *argc - 1); if (!isspace(*i)) break; i++; } (*argv)[*argc - 1] = malloc(strlen(i) + 1); strcpy((*argv)[*argc - 1], i); if (bool_option("verbose")) cio_out("argv[%d] = \"%s\"\n", *argc - 1, (*argv)[*argc - 1]); }
// a sample exported function int DLL_EXPORT check(word_t * self){ if(word_count(self) > 5 ) return 1; else return 0; }
void fe(u_char *command, u_char *args, u_char *subargs) { u_char *list = NULL, *templist = NULL, *placeholder, *oldlist = NULL, *sa, *vars, *var[255], *word = NULL, *todo = NULL; int ind, x, y, count, args_flag; unsigned display; for (x = 0; x < 255; var[x++] = NULL) ; list = next_expr(&args, '('); /* ) */ if (!list) { yell ("FE: Missing List for /FE"); return; } sa = subargs ? subargs : (u_char *) " "; malloc_strcpy(&templist, list); do { malloc_strcpy(&oldlist, templist); new_free(&templist); templist = expand_alias(NULL, oldlist, sa, &args_flag, NULL); } while (my_strcmp(templist, oldlist)); new_free(&oldlist); if (*templist == '\0') { new_free(&templist); return; } vars = args; if (!(args = my_index(args, '{'))) /* } */ { yell ("FE: Missing commands"); new_free(&templist); return; } *(args-1) = '\0'; ind = 0; while ((var[ind++] = next_arg(vars, &vars))) { if (ind == 255) { yell ("FE: Too many variables"); new_free(&templist); return; } } ind = ind ? ind - 1: 0; if (!(todo = next_expr(&args, '{'))) /* } { */ { yell ("FE: Missing }"); new_free(&templist); return; } count = word_count(templist); display = get_display(); placeholder = templist; for (x = 0; x < count;) { set_display_off(); for (y = 0; y < ind; y++) { word = ((x + y) < count) ? next_arg(templist, &templist) : NULL; add_alias(VAR_ALIAS, var[y], word); } set_display(display); x += ind; parse_line(NULL, todo, subargs ? subargs : empty_string(), 0, 0, 0); } set_display_off(); for (y = 0; y < ind; y++) { delete_alias(VAR_ALIAS, var[y]); } set_display(display); new_free(&placeholder); }
int main() { char* filename = "textfile.txt"; printf("Word count: %d\n", word_count(filename)); return 0; }
void terminate_process(char *addl_args) { register int i; int addl_args_len = strlen(addl_args) + 1; char *proc_c; char *sig_c; pid_t proc = 0; int sig = SIGTERM; int num_words = word_count(addl_args); if (num_words == 1) { if (isdigit(addl_args[0]) != 0) { kill(atoi(addl_args), SIGTERM); } else { ; /* failure */ } } else if (num_words > 1) { sig_c = (char *)malloc(addl_args_len); if (sig_c == NULL) { dk_err("Couldn't allocate memory for signal name / number"); } get_word(addl_args, sig_c, 1); if (isdigit(sig_c[0])) { sig = atoi(sig_c); } else { for (i = 0; i < NSIG; ++i) { if (!strcasecmp(sys_signame[i], sig_c)) { sig = i; break; } } } free(sig_c); proc_c = (char *)malloc(addl_args_len); if (proc_c == NULL) { dk_err("Couldn't allocate memory for process name / pid"); return; } get_word(addl_args, proc_c, 2); if (isdigit(proc_c[0])) { proc = (pid_t)atoi(proc_c); } else { ; /* match process by name */ } free(proc_c); kill(proc, sig); } end_transmission(); }
int main() { // get number of words in file int size = word_count(INPUT_PATH); // create empty array of size equal to count string original[size]; // populate array by passing it into the read file function read_file(original, size); // create empty array for scrambled words parallel to original // when scrambling, do not write over original array for comparisons // later on. string scrambled[size]; // for each word in original array, scramble and store in new array for (int index = 0; index < size; index++) { scrambled[index] = scramble(original[index]); } // write contents of scrambled to file for viewing/testing write_file(scrambled, size); start(size); int i = 0; string input; bool correct = false; int strikes = 0; string guess[3]; int index = 0; // used to iterate through guess array int total_correct = 0; /* * Would like to break this next part down into some smaller functions :) */ //iterate through each word while input given is not "exit" while(i < size && input != "exit"){ cout << "WORD " << i + 1 << ": " << scrambled[i] << endl << "Enter your guess or enter 'exit' to quit: "; input = get_input(); while (correct != true && strikes < 3 && input != "exit") { guess[index] = input; // set guess at current index equal to input cout << endl << "Scrambled Word: " << scrambled[i] << endl; for (int x = 0; x < index + 1; x++) { // prints each guess so far cout << "Guess " << x + 1 << ": " << guess[x] << endl; } // now test to see if correct if (guess[index] == original[i]) { correct = true; } else { strikes++; index++; cout << "Strikes: " << strikes << endl; cout << "Sorry! That was not correct." << endl << endl; // make sure strikes are not equal to three before prompting again. if (strikes < 3) { cout << "WORD " << i + 1 << ": " << scrambled[i] << endl; cout << "Enter your guess or enter 'exit' to quit: "; input = get_input(); } } } // determine what caused the loop to end (exit or max strikes) and take action accordingly if(input != "exit") { if(correct) { total_correct++; cout << "You guessed correctly!" << endl << endl; cout << "Score: " << total_correct << endl; } else { cout << "You've used all of your guesses." << endl << endl; cout << "Score: " << total_correct << endl; } cout << "On to the next word!" << endl << endl; strikes = 0; // reset strikes index = 0; // reset index of guesses correct = false; // reset correct i++; // increase to access next word } } if(input == "exit") { cout << endl << "You opted to end the game early."<< endl; } else { cout << "You have finished the list of words." << endl; if(total_correct == 20) { cout << endl << "Congratulations! You guess them all correctly!" << endl; } else { cout << endl << "You did not guess all of the words correctly. Better luck next time!" << endl; } } cout << "Thanks for playing!" << endl; cout << "Final Score: " << total_correct << "/" << size << endl << endl; cout << "END OF PROGRAM"; return 0; }
LRESULT CALLBACK thread_proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; RECT rc = {0}; UINT notify_duration = 0; HFONT hOldFont = NULL; switch (message) { case WM_LIBNOTIFYSHOW: if(notification_data) { /* deduce the allowed text width from the max width; see geometry for rationale */ rc.right = notification_window_width_max - (icon_size + (icon_padding * 3)); hdc = GetDC(hWnd); if(hdc) { HFONT hOldFont = NULL; HRGN hRgn = NULL; hOldFont = (HFONT) SelectObject(hdc, font_body); if(hOldFont) { DrawText(hdc, notification_data->body, -1, &rc, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL | DT_NOCLIP | DT_NOPREFIX | DT_EXTERNALLEADING); SelectObject(hdc, hOldFont); } ReleaseDC(hWnd, hdc); if(!hOldFont) return 0; /* exit if font selection failed */ /* calculate the actual bounding rectangle from the DrawText output */ notification_window_height = summary_body_divider + rc.bottom + (icon_padding * 3); notification_window_width = rc.right + icon_size + (icon_padding * 3); /* word count * milliseconds per word */ notify_duration = word_count(notification_data->body) * milliseconds_per_word; /* in case the calculation renders too low a value, replace it with a de facto minimum */ notify_duration = MAX(notify_duration, min_notification_timeout); /* get the screen area uncluttered by the taskbar */ if(SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0)) { LONG window_x = 0, window_y = 0; /* system tray @ right bottom */ if((rc.bottom != GetSystemMetrics(SM_CYSCREEN)) || (rc.right != GetSystemMetrics(SM_CXSCREEN))) { window_x = rc.right - (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor) - notification_window_width; window_y = rc.bottom - (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor) - notification_window_height; } else if(rc.left != 0) /* left bottom */ { window_x = rc.left + (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor); window_y = rc.bottom - (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor) - notification_window_height; } else /* right top */ { window_x = rc.right - (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor) - notification_window_width; window_y = rc.top + (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor); } /* resize and reposition the window */ MoveWindow(hWnd, window_x, window_y, notification_window_width, notification_window_height, TRUE); /* set the new positions to be used by the mouse over hook */ notification_window_rect.left = window_x; notification_window_rect.top = window_y; notification_window_rect.right = window_x + notification_window_width; notification_window_rect.bottom = window_y + notification_window_height; /* make it as a rounded rect. */ hRgn = CreateRoundRectRgn(0, 0, notification_window_width, notification_window_height, rounded_rect_edge, rounded_rect_edge); SetWindowRgn(notification_window, hRgn, TRUE); /* since bRedraw is set to TRUE in SetWindowRgn invalidation isn't required */ /*InvalidateRect(hWnd, NULL, TRUE);*/ /* show the window and set the timers for animation and overall visibility */ ShowWindow(hWnd, SW_SHOWNOACTIVATE); SetTimer(notification_window, TIMER_ANIMATION, fade_duration, NULL); SetTimer(notification_window, TIMER_NOTIFICATION, notify_duration, NULL); } } } break; case WM_LIBNOTIFYCLOSE: /* clean up and reset flags */ { if(hook_mouse_over) { UnhookWindowsHookEx(hook_mouse_over); hook_mouse_over = NULL; } KillTimer(hWnd, TIMER_ANIMATION); KillTimer(hWnd, TIMER_NOTIFICATION); is_fading_out = FALSE; ShowWindow(hWnd, SW_HIDE); } break; case WM_PAINT: if(notification_data && notification_data->summary && notification_data->body && notification_data->icon) { hdc = BeginPaint(hWnd, &ps); SetTextColor(hdc, RGB(255, 255, 255)); SetBkMode(hdc, TRANSPARENT); hOldFont = (HFONT) SelectObject(hdc, font_summary); if(hOldFont) { /* set the padding as left offset and center the icon horizontally */ DrawIcon(hdc, icon_padding, (notification_window_height / 2) - (icon_size / 2), notification_data->icon); /* calculate and DrawText for both summary and body based on the geometry given above */ rc.left = icon_size + (icon_padding * 2); rc.right = notification_window_width - icon_padding; rc.top = icon_padding; rc.bottom = summary_body_divider + (icon_padding * 2); DrawText(hdc, notification_data->summary, -1, &rc, DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); if(SelectObject(hdc, font_body)) { rc.top = rc.bottom; rc.bottom = notification_window_height - icon_padding; DrawText(hdc, notification_data->body, -1, &rc, DT_WORDBREAK | DT_EDITCONTROL | DT_NOCLIP | DT_NOPREFIX | DT_EXTERNALLEADING); } SelectObject(hdc, hOldFont); } EndPaint(hWnd, &ps); } break; case WM_DESTROY: PostQuitMessage(0); break; case WM_TIMER: if(IsWindowVisible(hWnd)) { if(wParam == TIMER_ANIMATION) /* notification animation timer */ { if(is_fading_out) { if(notification_window_alpha > 5) { notification_window_alpha -= 25; SetLayeredWindowAttributes(notification_window, 0, notification_window_alpha, LWA_ALPHA); } else { /* once fully faded out, self destroy and reset the flags */ KillTimer(hWnd, TIMER_ANIMATION); is_fading_out = FALSE; notification_window_alpha = 0; PostMessage(hWnd, WM_LIBNOTIFYCLOSE, 0, 0); } } else { if(notification_window_alpha < 250) { notification_window_alpha += 25; SetLayeredWindowAttributes(notification_window, 0, notification_window_alpha, LWA_ALPHA); } else { /* self destory as alpha reaches the maximum */ KillTimer(hWnd, TIMER_ANIMATION); notification_window_alpha = 255; /* set the mouse over hook once the window is fully visible */ hook_mouse_over = SetWindowsHookEx(WH_MOUSE_LL, mouse_over_hook_proc, (HINSTANCE) GetModuleHandle(NULL), 0); } } } else /* notification duration timer */ { /* self destruct once timed out */ KillTimer(hWnd, TIMER_NOTIFICATION); /* kill the hook set by animation timer */ if(hook_mouse_over) { UnhookWindowsHookEx(hook_mouse_over); hook_mouse_over = NULL; } /* start fading out sequence */ is_fading_out = TRUE; SetTimer(hWnd, 1, fade_duration, NULL); } } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }