soulB::checks_returns soulCH::lock_match() { /* Check if lock wanted */ const char *lock_status; int answer=0; if((db_io->get_config(lock_status,lock_switch,0,NULL,input->ip_num)) != TRUE) return CHECKS_ERROR; if(valid_answer(lock_status,answer)) return CHECKS_ERROR; if(answer) return RETURN_DENIED; return CONTINUE; }
int main(int argc, char *argv[]) { // An array of 4 players, may need to be a pointer if you want it set dynamically player players[NUM_PLAYERS]; // Input buffer and and commands //char buffer[BUFFER_LEN] = { 0 }; // Display the game introduction and initialize the questions initialize_game(); // Prompt for players names printf("This is Jeopardy \n"); // initialize each of the players in the array for(int i = 0; i < 4; i++) { players[i].score = 0; printf("Enter player name: "); scanf("%s", (char *) &players[i].name); } // Perform an infinite loop getting command input from users until game ends //while (fgets(buffer, BUFFER_LEN, stdin) != NULL) while(!answered_status()) { system("clear"); char selected_player[MAX_LEN] = ""; char selected_category[MAX_LEN] = ""; int selected_val = 0; do { if(strcmp(selected_player, "") != 0) printf("The player %s was not found", selected_player); printf("Enter first player's name: "); scanf("%s", (char *) &selected_player); } while(!player_exists(players, 4, selected_player)); do { if(selected_val != 0) printf("Invalid selection"); printf("Enter category: "); getchar(); fgets((char *) selected_category, MAX_LEN, stdin); strtok(selected_category, "\n"); printf("Enter: "); scanf("%d", (int *) &selected_val); } while(already_answered(selected_category, selected_val)); system("clear"); display_question(selected_category, selected_val); char *answer[MAX_LEN] = {0}; getchar(); fgets((char *) answer, MAX_LEN, stdin); char *tokenize_answer; tokenize((char *) answer, &tokenize_answer); if(tokenize_answer == NULL) printf("Try again"); else if(valid_answer(selected_category, selected_val, tokenize_answer)) { printf("Correct Answer!"); printf("%s gains %d points \n", selected_player, selected_val); update_score(players, 4, selected_player, selected_val); } else { printf("Wrong Answer!"); int num = get_question_number(selected_category, selected_val); printf("Correct answer was: %s", questions[num].answer); } track_answered(selected_category, selected_val); // Call functansions from the questions and players source files // Execute the game until all questions are answered // Display the final results and exit } show_results(players, 4); getchar(); return EXIT_SUCCESS; }
int main (int argc, char **argv) { int ret = EXIT_SUCCESS; program_name = argv[0]; parse_line (argv); if (!answer_chars) answer_chars = DEFAULT_ANSWER_CHARS; if (question && *question) { for (;;) { fputs (question, stdout); if (question[strlen (question) - 1] != '?') fputc ('?', stdout); fputs (" [", stdout); if (answer_chars && *answer_chars) { size_t i; for (i = 0; answer_chars[i]; ++i) { fputc (answer_chars[i], stdout); if (answer_chars[i + 1]) fputc ('/', stdout); } } fputc (']', stdout); if (newline) fputc ('\n', stdout); else fputc (' ', stdout); char user_answer = fgetc (stdin); if (user_answer == EOF) { ret = -2; break; } if (!valid_answer (user_answer)) { printf ("`%c' unrecognized, try again...\n", user_answer); continue; } size_t r; for (r = 0; answer_chars[r]; ++r) { if (user_answer == answer_chars[r]) { ret = (int) r; break; } } break; } } else { print_usage (1); ret = -1; } return ret; }