void test_get_user_input(CuTest *tc) { printf("Type something and hit return (testing user input): "); char * user_input = get_user_input(-1); CuAssertPtrNotNullMsg(tc, "user input pointer is null", user_input); int equal_strings = strcmp("", user_input); CuAssertTrue(tc, equal_strings != 0); }
int main(void) { char guess[100]; int count; for (count = 0; count < 3 && strcmp(SECRET, guess) != 0; count++) { printf("Guess the word!\nHint: You find it in the living room or kitchen or sitting room or bedroom...or all of the above!.\n"); get_user_input(guess); /*calls get_user_input function*/ if (strcmp(SECRET, guess) == 0) { printf("Correct guess - well done\n"); } else { printf("Sorry %s is not the secret word\n"); } } if (strcmp (SECRET, guess) != 0) { printf("Game Over. You have used your three chances."); } return 0; }
void game_loop(void) { bool redraw = true; al_start_timer(timer); int frame = 0; while (!done) { ALLEGRO_EVENT event; al_wait_for_event(event_queue, &event); if (event.type == ALLEGRO_EVENT_TIMER) { redraw = true; //update_logic(); } else if (event.type == ALLEGRO_EVENT_KEY_DOWN) { if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { done = true; } get_user_input(event.keyboard.keycode); } if (redraw && al_is_event_queue_empty(event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(0,0,0)); update_graphics(); al_flip_display(); } frame++; } }
static void try_redirect(newtComponent c) { struct ast_chan *chan; char dest[256]; struct message *m; char channame[256]; char tmp[80]; char *context; chan = newtListboxGetCurrent(c); if (chan) { strncpy(channame, chan->name, sizeof(channame) - 1); snprintf(tmp, sizeof(tmp), "Enter new extension for %s", channame); if (get_user_input(tmp, dest, sizeof(dest))) return; if ((context = strchr(dest, '@'))) { *context = '\0'; context++; manager_action("Redirect", "Channel: %s\r\nContext: %s\r\nExten: %s\r\nPriority: 1\r\n", chan->name,context,dest); } else { manager_action("Redirect", "Channel: %s\r\nExten: %s\r\nPriority: 1\r\n", chan->name, dest); } m = wait_for_response(10000); if (!m) { show_message("Hangup Failed", "Timeout waiting for response"); } else if (strcasecmp(get_header(m, "Response"), "Success")) { show_message("Hangup Failed", get_header(m, "Message")); } } }
static rc_t populate_tool_ctx( tool_ctx_t * tool_ctx, const Args * args ) { rc_t rc = ArgsParamValue( args, 0, ( const void ** )&( tool_ctx -> accession_path ) ); if ( rc != 0 ) ErrMsg( "ArgsParamValue() -> %R", rc ); else { tool_ctx -> lookup_filename[ 0 ] = 0; tool_ctx -> index_filename[ 0 ] = 0; tool_ctx -> dflt_output[ 0 ] = 0; get_user_input( tool_ctx, args ); encforce_constrains( tool_ctx ); get_environment( tool_ctx ); rc = make_temp_dir( &tool_ctx -> temp_dir, tool_ctx -> requested_temp_path, tool_ctx -> dir ); } if ( rc == 0 ) rc = handle_accession( tool_ctx ); if ( rc == 0 ) rc = handle_lookup_path( tool_ctx ); if ( rc == 0 && tool_ctx -> output_dirname != NULL ) { if ( !dir_exists( tool_ctx -> dir, "%s", tool_ctx -> output_dirname ) ) rc = create_this_dir_2( tool_ctx -> dir, tool_ctx -> output_dirname, true ); } if ( rc == 0 ) { if ( tool_ctx -> output_filename == NULL ) { if ( tool_ctx -> output_dirname == NULL ) rc = make_output_filename_from_accession( tool_ctx ); else rc = make_output_filename_from_dir_and_accession( tool_ctx ); } else { if ( tool_ctx -> output_dirname == NULL ) rc = adjust_output_filename( tool_ctx ); else rc = adjust_output_filename_by_dir( tool_ctx ); } } if ( rc == 0 ) rc = Make_FastDump_Cleanup_Task ( &( tool_ctx -> cleanup_task ) ); /* cleanup_task.c */ if ( rc == 0 ) rc = Add_Directory_to_Cleanup_Task ( tool_ctx -> cleanup_task, get_temp_dir( tool_ctx -> temp_dir ) ); return rc; }
bool MenuMgr::execute() { MenuCmd* pCmd; do { show(); int userInput = get_user_input(); pCmd = select( userInput ); } while( pCmd->execute() ); return true; }
int main() { signal(SIGINT, SIG_IGN); int return_code = 0; char *user_input = (char*)malloc(sizeof(char)*MAX_USER_INPUT); user_input = (char*)memset(user_input,MAX_USER_INPUT*sizeof(char), 0); while(1) { return_code = get_user_input(return_code, user_input); strcpy(user_input,""); } }
void main() { minf = compute_minf(); maxf = compute_maxf(); initialize_graphic_mode(); draw_borders(); print_usage_text(); scale_function(); initialize_left_area(); redraw_right_area(); get_user_input(); closegraph(); }
static bool set_refresh_timeout() { static char buf[4]; mvprintw(1, 0, "%s (currently %u): ", _("Set refresh time out"), time_out); memset(buf, '\0', sizeof(buf)); get_user_input(buf, sizeof(buf) - 1); show_tab(0); unsigned time = strtoul(buf, NULL, 0); if (!time) return 0; if (time > 32) time = 32; time_out = time; return 1; }
void execute_load(char* command, ListT* tasks, TaskT** current_task) { ListT* files; //check if we should save if (tasks != NULL && tasks->size > 0) { char* save_before_load; printf("Save before load? (y)/n? "); get_user_input(&save_before_load); if (save_before_load != NULL && strlen(save_before_load) > 0 && save_before_load[0] == 'y' || save_before_load[0] == 'Y') { printf("saving\n"); execute_save(command, tasks, current_task); } } files = get_loadables(YES); if (files->size > 0) { ListT* _tasks; TaskT* loaded_task; int user_selection; char *filename, *abs_file;; while ((user_selection = get_numeric_input("Choose which file to load? ")) < 0 || user_selection >= files->size) ; DEBUG("user_selection %d", user_selection); printf("\n\n"); filename = list_obj_at_idx(files, user_selection); abs_file = malloc(strlen(filename) + 20); sprintf(abs_file, "tasks/%s", filename); //destroy all tasks in memory list_empty(tasks, YES); _tasks = task_read(abs_file); list_copy(tasks, _tasks); *current_task = tasks != NULL && tasks->size > 0 ? list_obj_at_idx(tasks, 0) : NULL; list_destroy(_tasks); free(abs_file); } else { puts("No files to load."); } list_destroy(files); }
void execute_child(char* command, ListT* tasks, TaskT** current_task) { char* child_text; TaskT* child; if (is_command_only(command)) { printf("What do you need to get done?"); get_user_input(&child_text); } else { child_text = get_text_from_command(command); } child = Task(child_text); task_add_child(*current_task, child); *current_task = child; }
int main() { char word[MAX_WORD_LEN]; /* Word to guess (from file) */ char mask[MAX_WORD_LEN]; /* Masked word (shown on screen) */ int ch; /* User selection */ int count; /* Number of guesses */ int result; /* Winner */ int len; /* -------------------- Programstart -----------------*/ srand( time(0) ); while( true ){ /* * Init section */ printf( "Valkommen till HANG MAN 2011\n"); printf( "Du har %d gissningar på dig (avbryt med 0)\n", MAX_GUESS ); printf( "Datorn har nu valt ett ord på %d bokstaver\n", len ); while( true ){ /* GAME MAIN LOOP */ } if( result == WIN ){ printf("Grattis du vann!\n"); }else if( result == LOOSE ){ printf("Tyvarr du forlorade ordet var: %s\n", word); }else{ printf("Avbrutet\n"); } ch = get_user_input("Vill du spelas igen (j/n)?): "); if( ch == 'n' || ch == 'N' ){ break; } } return 0; }
//----------------------------------------------------------------------------------------------- //example for detach void edit_document(std::string const& filename) { open_document_and_display_gui(filename); while(!done_editing()) { user_command cmd= get_user_input(); if(cmd.type == open_new_document) { std::string const new_name = get_filename_from_user(); std::thread t(edit_docment,new_name); t.detach(); } else { process_user_input(cmd); } } }
//====================================================================== void quick_align::interaction(){ std::string key_user_wants_to_satrt_quick_mirror_alignment ="q"; add_control(key_user_wants_to_satrt_quick_mirror_alignment, "start quick mirror alignment"); std::string key_user_wants_to_end_quick_mirror_alignment ="back"; add_control(key_user_wants_to_end_quick_mirror_alignment, "back to main menu"); std::string user_input; std::stringstream out; bool flag_user_wants_to_align_mirrors = true; do{ //============================================================== // prompt snapshot options to command line //============================================================== update_status_prompt(get_quick_alignment_prompt()); //============================================================== // get input of user via command line //============================================================== get_user_input(); //============================================================== // interpret answer of user //============================================================== if(valid_user_input. compare(key_user_wants_to_end_quick_mirror_alignment)==0){ flag_user_wants_to_align_mirrors = false; } //================================================================== if(valid_user_input. compare(key_user_wants_to_satrt_quick_mirror_alignment)==0){ run_alignment(); } //================================================================== }while(flag_user_wants_to_align_mirrors); }
static int ca_root_certificate_info(HSM_CLIENT_HANDLE hsm_handle) { int result; char* leaf_certificate = NULL; char* root_cert = NULL; char* common_name = NULL; if ((root_cert = hsm_client_riot_get_root_cert(hsm_handle)) == NULL) { (void)printf("Failure getting root certificate\r\n"); result = __LINE__; } else { (void)printf("root cert:\r\n%s\r\n", root_cert); if ((common_name = get_user_input("Enter the Validation Code (Press enter when finished): ", MAX_VALIDATION_CODE_LEN)) == NULL) { (void)printf("Failure with validation code\r\n"); result = __LINE__; } else if ((leaf_certificate = hsm_client_riot_create_leaf_cert(hsm_handle, common_name)) == NULL) { (void)printf("Failure setting leaf certificate\r\n"); result = __LINE__; } else { (void)printf("Leaf Certificate:\r\n%s\r\n", leaf_certificate); result = 0; } free(root_cert); free(leaf_certificate); free(common_name); } return result; }
/* * n1 * Polls the user for the name of a file and a node. * Sends the file character by character to the node via special FIFO-based protocol. */ int main(int argc, char *argv[]) { char *filename, *contents; long n_chars; int write_child; int node; packet p; do { // Get filename and node number from user. get_user_input(&filename, &node); // Get contents of file. n_chars = get_file_contents(filename, &contents); // Send file data to node. send_data(1, node, n_chars, contents); // Receive acknowledgement packet from node. recv_acknowledge(1, node); free(filename); free(contents); } while (!should_quit()); // Send exit message to all child nodes. p.data = END_OF_TRANSMISSION; for (int i = NUM_NODES; i > 1; i--) { write_child = get_link(1, i, WRITE); p.dest = i; send_packet(write_child, p); close(write_child); recv_acknowledge(1, i); } return 0; }
/* This is the magic location that prints prompts * and gets data back from the user */ static int file_get(struct in_str *i) { int ch; ch = 0; /* If there is data waiting, eat it up */ if (i->p && *i->p) { ch = *i->p++; } else { /* need to double check i->file because we might be doing something * more complicated by now, like sourcing or substituting. */ while (!i->p || strlen(i->p) == 0) { get_user_input(i); } i->promptmode = 2; if (i->p && *i->p) { ch = *i->p++; } debug_printf("b_getch: got a %d\n", ch); } return ch; }
void get_number(char ** _number, char name []) { printf("What is your magic number, %s?\n", name); get_user_input(_number, false); }
void create_circuit(){ circuito cir; dev device; char dev_name[7]; uint8_t index; uint8_t i=0; boolean found=false; printf("new circuit name? "); get_user_input(cir.nome,sizeof(cir.nome)); printf("input device name? "); get_user_input(dev_name,sizeof(dev_name)); while(load_from_file("devs.lst",(uint8_t *)&device,sizeof(device),i)){ blink_led(); if (strcmp(device.name,dev_name)==0){ found=true; break; } i++; } if (found){ cir.botao.addr=device.addr; printf("input index? "); get_user_input((char *)&index,1); index-='0'; cir.botao.index=index; }else{ printf("name not found\r\n"); return; } i=0; found=false; printf("output device name? "); get_user_input(dev_name,sizeof(dev_name)); while(load_from_file("devs.lst",(uint8_t *)&device,sizeof(device),i)){ blink_led(); if (strcmp(device.name,dev_name)==0){ found=true; break; } i++; } if (found){ cir.luz.addr=device.addr; printf("output index? "); get_user_input((char *)&index,1); index-='0'; cir.luz.index=index; cir.luz.estado=LOW; }else{ printf("name not found\r\n"); return; } printf("save?(y/n)\r\n"); get_user_input((char *)&index,1); if (index=='y'){ file=SD.open("cirs.lst",FILE_WRITE); if (file){ file.write((byte *)&cir,sizeof(cir)); } file.close(); printf("saved\r\n"); }else{ return; } }
int main(int argc, char **argv) { int retc = 0, c; char *handler_name = NULL; char selection; if (argc < 3) { printf("Too few arguments\n"); print_usage(); exit(1); } else if (argc > 3) { printf("Too many arguments\n"); print_usage(); exit(1); } while ((c = getopt (argc, argv, "n:s")) != EOF) { switch (c) { case 'n': handler_name = optarg; break; default: exit(1); break; } } while (get_user_input(&selection, topmenu)) { switch (selection) { case RESOURCE: get_user_input(&selection, resource_menu); switch (selection) { case 1: case 2: inject_resource_event(handler_name, selection); break; case 3: inject_resource_add_event(handler_name); break; default: break; } break; case DOMAIN: get_user_input(&selection, domain_menu); inject_domain_event(handler_name, selection); break; case SENSOR: inject_sensor_event(handler_name); break; case SENSOR_ENABLE_CHANGE: inject_sensorec_event(handler_name); break; case HOTSWAP: inject_hotswap_event(handler_name); break; case WATCHDOG: inject_watchdog_event(handler_name); break; case SOFTWARE: inject_software_event(handler_name); break; case Oem: inject_oem_event(handler_name); break; case USER: inject_user_event(handler_name); break; default: printf("Unrecognized selection\n"); break; } } return 0; }
/** * manages the running of the program, initialises data structures, loads * data and handles the processing of options. The bulk of this function * should simply be calling other functions to get the job done. **/ int main(int argc, char **argv) { /* Represents the data structures to manage the system */ struct ppd_system system; struct menu_item menu[NUM_MENU_ITEMS]; char input[NUM_MENU_INPUT], *error; int option, i; BOOLEAN exit = FALSE; /* Validate command line arguments */ if ( argc != NUM_ARGS) { printf("Usage: ./playme <stock> <coins>\n\n"); return EXIT_FAILURE; } else { if(argv[ITEM_FILE_INDEX] == 0) { printf("stock_file failed!\n"); printf("Please make sure to input file name correctly.\n\n"); return EXIT_FAILURE; } if(argv[COIN_FILE_INDEX] == 0) { printf("coins_file failed!\n"); printf("Please make sure to input file name correctly.\n\n"); return EXIT_FAILURE; } } /* Init the system */ if(system_init(&system) != TRUE) { printf("System failed to initialise!\n"); system_free(&system); return EXIT_FAILURE; } /* Load data */ if(load_data(&system, argv[COIN_FILE_INDEX], argv[ITEM_FILE_INDEX]) != TRUE) { printf("Failed to load data!\n"); system_free(&system); return EXIT_FAILURE; } /* Test if everything has been initialised correctly */ #if 0 if(!display_items(&system) || !display_coins(&system)) abort_program(&system); #endif /* Initialise the menu system */ init_menu(menu); while(!exit) { /* Loop, asking for options from the menu */ for(i = 0; i < NUM_MENU_ITEMS; i++) { if(i == SELECT_DEFAULT) printf("\n\n== Default Selections ==\n========================\n"); else if(i == SELECT_ADMIN) printf("\n== Admin Selections ==\n========================\n"); printf("%d. %s\n", i + 1, menu[i].name); } while(!exit) { printf("\nPlease select what you would like to do: "); /* Get user input and assign to variable */ i = get_user_input(input, NUM_MENU_INPUT); /* Check for return to menu */ if(i == RTM) { printf("You have no where to return to!\n"); continue; } /* Check for invalid input */ if(i == FAILURE) { printf("Your text was too long!\n"); continue; } /* Convert given input to int and assign to option */ option = (int) strtol(input, &error, 0) - 1; /* Check if converted string inside menu range */ if(option >= 0 && option <= NUM_MENU_ITEMS) exit = TRUE; /* For all other values, echo output outside of range */ else printf("Input outside of range!\n"); } /* Reset exit BOOLEAN for part 2 */ exit = FALSE; /* Run each option selected */ if(menu[option].function(&system) != TRUE) printf("Option '%s' failed to complete!\n", menu[option].name); } return EXIT_SUCCESS; }
//====================================================================== void sccan_point_pair_handler:: interaction(){ std::string key_user_wants_to_take_more_sccan_points ="m"; std::string key_show_list_of_sccan_points_in_current_directory ="s"; std::string key_reset_exposure_times ="r"; std::string key_show_star_position_indicator_image ="i"; std::string key_modify_sigma_threshold ="sigma"; std::string key_modify_recognition_radius ="radius"; std::string key_user_wants_to_end_taking_sccan_points ="back"; std::string key_modify_star_cam_desired_max_rel_respone ="star_cr"; std::string key_modify_refl_cam_desired_max_rel_respone ="refl_cr"; std::string key_max_valid_exposure_time = "max_exp"; add_control(key_user_wants_to_take_more_sccan_points, "aquire >N< additional sccan points"); add_control (key_show_list_of_sccan_points_in_current_directory, "show list of sccan_points in current directory"); add_control (key_show_star_position_indicator_image, "show star position indicator image"); add_control (key_reset_exposure_times, "reset exposure times of cameras"); add_control (key_modify_sigma_threshold, "modify sigma threshold"); add_control (key_modify_recognition_radius, "modify recognition radius"); add_control (key_modify_star_cam_desired_max_rel_respone, "modify star camera max desired rel. respone"); add_control (key_modify_refl_cam_desired_max_rel_respone, "modify reflector camera max desired rel. respone"); add_control (key_user_wants_to_end_taking_sccan_points, "back to main menu"); add_control(key_max_valid_exposure_time, "set max valid exposure time"); std::string user_input; std::stringstream out; bool flag_user_wants_to_acquire_sccan_points = true; do{ //============================================================== // prompt snapshot options to command line //============================================================== update_list_of_runs_in_current_directory(); update_status_prompt(get_prompt()); //============================================================== // get input of user via command line //============================================================== get_user_input(); //============================================================== // interpret answer of user //============================================================== //std::cout<<"valid_user_input: "<<valid_user_input<<std::endl; //============================================================== if(valid_user_input.compare (key_user_wants_to_end_taking_sccan_points)==0){ flag_user_wants_to_acquire_sccan_points = false; } //================================================================== if(valid_user_input.compare (key_user_wants_to_take_more_sccan_points)==0){ int number_of_sccan_points_to_be_acquired = ask_user_for_integer ("Enter number of sccan points to be acquired",0,1e4); acquire_sccan_points(number_of_sccan_points_to_be_acquired); } //================================================================== if(valid_user_input.compare( key_show_list_of_sccan_points_in_current_directory)==0){ disp_list_of_sccan_points_in_current_directory(); } //================================================================== if(valid_user_input.compare(key_modify_sigma_threshold)==0){ threshold_in_sigmas_for_star_detection = ask_user_for_non_zero_float( "Enter threshold for star detection in sigmas of image noise", 0.0,100.0); } //================================================================== if(valid_user_input.compare(key_modify_recognition_radius)==0){ star_recognition_one_sigma_radius_in_degrees = ask_user_for_non_zero_float ("Enter new star recognition radius",0.0,180.0); } //================================================================== if( valid_user_input.compare(key_show_star_position_indicator_image)==0) { display_star_position_indicator_image(); } //================================================================== if(valid_user_input.compare(key_reset_exposure_times)==0){ reset_exposure_times(); } //================================================================== if(valid_user_input.compare( key_modify_star_cam_desired_max_rel_respone)==0){ star_camera_desired_max_relative_camera_response = ask_user_for_non_zero_float( "enter new relative star camera response (0,1)",0.01,0.99); } //================================================================== if(valid_user_input.compare( key_modify_refl_cam_desired_max_rel_respone)==0){ reflector_camera_desired_max_relative_camera_response = ask_user_for_non_zero_float( "enter new relative reflector camera response (0,1)",0.01,0.99); } //================================================================== if(valid_user_input.compare( key_max_valid_exposure_time)==0){ max_exposure_time_until_sccan_point_is_not_valid_anymore = ask_user_for_non_zero_float( "enter new maximal valid exposure time [ms]",0.01,60000); } //================================================================== }while(flag_user_wants_to_acquire_sccan_points); }
static int main_game_loop(struct env *board, struct creature *pac, struct creature *ghost, int cnt) { unsigned long time_to_sleep; enum dir_t direction; int i, won = 0; draw_board(board); box_print(0, 0, "Welcome. Hit any key to start :)"); update_view(); blocking_input(); do { /* set up and place the players (ghosts etc) */ if (!init_players(board, pac, ghost, cnt)) return 0; /* blank out screen, ready for action */ reset_view(); draw_board(board); time_to_sleep = INITIAL_DELAY; for (;;) { /* check for user input */ direction = get_user_input(); if (direction == QUIT) break; move_pac(board, pac, direction); draw_creature(board, pac); erase_tail(board, pac); /* Move and draw N ghosts. */ for (i=0; i<cnt; i++) { ghost_move(board, &(ghost[i]), i); draw_creature(board, &(ghost[i])); erase_tail(board, &(ghost[i])); } /* Up the score if we got any cherries, * then print the new (or old) score. */ pick_up_cherries(board, pac); print_stat(board); /* update the whole screen */ update_view(); /* Check if there's any more cherries to * pick, otherwise the game is won. */ won = game_won(board); if (won) break; if (pac_caught(pac, ghost, cnt)) { down_lives(board); break; } /* * Sleep for a short while. This function is not * ANSI/ISO-C. */ usleep(time_to_sleep); if (time_to_sleep > MIN_DELAY) time_to_sleep -= DEC_DELAY; } } while (direction != QUIT && !won && lives_left(board) > 0 && play_again()); finish(won, lives_left(board)); return 1; }
int main() { int result; if (platform_init() == 0 && initialize_hsm_system() == 0) { HSM_CLIENT_HANDLE hsm_handle; if ((hsm_handle = hsm_client_riot_create()) == NULL) { (void)printf("Failure getting common name\r\n"); result = __LINE__; } else { char* enroll_type = get_user_input("Would you like to do Individual (i) or Group (g) enrollments: ", 1); if (enroll_type != NULL) { if (enroll_type[0] == 'g' || enroll_type[0] == 'G') { if (ca_root_certificate_info(hsm_handle) != 0) { result = __LINE__; } else { result = 0; } } else { if (alias_certificate_info(hsm_handle) != 0) { result = __LINE__; } else { result = 0; } } free(enroll_type); } else { (void)printf("Invalid option specified\r\n"); result = __LINE__; } hsm_client_riot_destroy(hsm_handle); } deinitialize_hsm_system(); platform_deinit(); } else { (void)printf("Failed calling platform_init\r\n"); result = __LINE__; } (void)printf("Press any key to continue:\r\n"); (void)getchar(); return result; }
int main2() { char word[MAX_WORD_LEN]; /* Word to guess (from file) */ char mask[MAX_WORD_LEN]; /* Masked word (shown on screen) */ int ch; /* User selection */ int count; /* Number of guesses */ int result; /* Winner */ int len; char *hangman[] = { "_ _ _ _ _\n", // Rad ett vid 1:a felgissningen " | \n", // Rad ett vid 2:a felgissningen " 0 \n", // Rad ett vid 3:e felgissningen " // | \\ \n", // Rad ett vid 4:e felgissningen " | \n", // Rad ett vid 5:e felgissningen " //\\ \n" // Rad ett vid 6:e felgissningen }; /* -------------------- Programstart -----------------*/ srand( time(0) ); while( 1 ){ /* * Init section */ // slumpa fram ett ord printf( "Välkommen till HANG MAN 2013\n"); printf( "Du har %d gissningar p dig (avbryt med 0)\n", MAX_GUESS ); printf( "Datorn har nu valt ett ord p %d bokstaver\n", len ); while( 0 ){ // spel-loop // hämta en bokstav // finns bokstaven i ordet? // visa } if( result == WIN ){ printf("Grattis du vann!\n"); }else if( result == LOOSE ){ printf("Tyvarr du forlorade ordet var: %s\n", word); }else{ printf("Avbrutet\n"); } ch = get_user_input("Vill du spela igen (j/n)?)> "); if( ch == 'n' || ch == 'N' ){ break; } } return 0; }
//------------------------------------------------------------------------------ void sccan_point_analysis::interaction(){ std::string key_fill_sccan_point_matrix ="f"; add_control(key_fill_sccan_point_matrix,"fill sccan point matrix"); std::string key_show_sccan_point_matrix ="s"; add_control(key_show_sccan_point_matrix,"show sccan point matrix"); std::string key_analyse_sccan_point_matrix ="a"; add_control(key_analyse_sccan_point_matrix, "analyse sccan point matrix"); std::string key_toggle_light_flux_normalizing ="n"; add_control(key_toggle_light_flux_normalizing, "toggle mirror response normalizing"); std::string key_toggle_max_response_estimation_method ="method"; add_control(key_toggle_max_response_estimation_method, "toggle max response estimation method"); std::string key_draw_all_mirror_response_maps ="draw"; add_control(key_draw_all_mirror_response_maps, "draw all mirror response maps"); std::string key_toggle_multithread ="m"; add_control(key_toggle_multithread,"toggle multithread"); std::string key_substract_global_direction_offset = "sub_off"; add_control(key_substract_global_direction_offset," toggle sub. global direction offset"); std::string key_user_wants_to_end_analysis ="back"; add_control(key_user_wants_to_end_analysis,"back to main menu"); std::string user_input; std::stringstream out; bool flag_user_wants_to_analyse = true; do{ // prompt snapshot options to command line update_status_prompt(get_analysis_prompt()); // get input of user via command line get_user_input(); // interpret answer of user if(valid_user_input.compare(key_user_wants_to_end_analysis)==0) flag_user_wants_to_analyse = false; if(valid_user_input.compare(key_fill_sccan_point_matrix)==0) fill_sccan_matrix(); if(valid_user_input.compare(key_show_sccan_point_matrix)==0) display_sccan_matrix_prompt(); if(valid_user_input.compare(key_analyse_sccan_point_matrix)==0) run_anaysis(); if(valid_user_input.compare(key_draw_all_mirror_response_maps)==0){ for(uint mirror_it=0; mirror_it<get_number_of_mirrors(); mirror_it++ ) draw_mirror_response(mirror_it); } if(valid_user_input.compare(key_toggle_light_flux_normalizing)==0) normalize_mirror_response = ! normalize_mirror_response; if(valid_user_input.compare(key_toggle_multithread)==0) use_multithread =! use_multithread; if(valid_user_input.compare(key_toggle_max_response_estimation_method)==0) max_only_instead_of_CoG =! max_only_instead_of_CoG; if(valid_user_input.compare(key_substract_global_direction_offset)==0) substract_global_offset =! substract_global_offset; }while(flag_user_wants_to_analyse); }
void get_name(char ** name) { printf("What is your name?\n"); get_user_input(name, true); }
int main(void) { int userInput; size_t i; record student_record; name student_name; record_list student_list; student_list.nalloc = 0; student_list.nused = 0; list_init(&student_list); do { displayMenu(); userInput = get_user_input(); if(userInput == ENTER_RECORDS) { while (userInput != EOF) { while (userInput != EOF && ask_for_student_id(&student_record, &userInput)) { ; } while(userInput != EOF && ask_for_last_name(&student_name, &userInput)) { ; } while (userInput != EOF && ask_for_first_name(&student_name, &userInput)) { ; } while (userInput != EOF && ask_for_score(&student_record, &userInput)) { ; } if (userInput != EOF) { student_record.name = student_name; list_insert(&student_list, &student_record); fprintf(stderr, "Please enter another record.\n"); } } } if (userInput == RECORDS_BY_ID) { if (student_list.nused == 0) { fprintf(stderr, "No data to display.\n"); } else { qsort(student_list.data, student_list.nused, sizeof(student_list.data[0]), cmp_by_id); for (i = 0; i < student_list.nused; i++) { display_record(student_list.data[i]); } } } if (userInput == RECORDS_BY_NAME) { if (student_list.nused == 0) { fprintf(stderr, "No data to display.\n"); } else { qsort(student_list.data, student_list.nused, sizeof(student_list.data[0]), cmp_by_name); for (i = 0; i < student_list.nused; i++) { display_record(student_list.data[i]); } } } } while (userInput != QUIT); list_destroy(&student_list); return 0; }