/* ================== addAirport ================= This function adds another element of data into both the tree and hash table, through the user's input from keyboard. Pre pHeader - pointer to HEAD structure Post Return true if success false if fails */ bool addAirport (HEAD* pHeader) { // Local Declarations bool result = false; DATA tempAirport; DATA* newAirport = NULL; char tempCode [28]; char tempName [128]; int i; printf ("Enter airport code: "); scanf (" %s", tempCode); if (strlen(tempCode) != 3) { printf("Your airport code has to have 3 characters\n"); return result; } for (i = 0; i<strlen(tempCode); i++) { tempCode[i] = toupper(tempCode[i]); } strcpy(tempAirport.arpCode, tempCode); newAirport = findHash(pHeader->pHash, &tempAirport); if (newAirport == NULL) { if (!(newAirport = (DATA*) malloc(sizeof(DATA)))) { printf("Error allocating new airport\n"); exit(100); } strcpy(newAirport->arpCode, tempCode); printf("Enter airport city: "); scanf(" %[^\n]", tempName); newAirport->city = (char*) calloc(strlen(tempName) + 1, sizeof(char)); strcpy(newAirport->city, tempName); printf("Enter airport latitude: "); while(!(scanf("%f", &newAirport->latitude))) { printf("Invalid input, please try entering the latitude again: "); while(getchar() != '\n'); } printf("Enter airport longitude: "); while(!(scanf("%f", &newAirport->longitude))) { printf("Invalid input, please try entering the longitude again: "); while(getchar() != '\n'); } insertHash(pHeader->pHash, newAirport); BST_Insert(pHeader->pTree, newAirport); result = true; } else{ printf("This airport already exists\n"); processScreen(newAirport); } return result; } // addAirport
void StellaEnvironment::emulate(Action player_a_action, Action player_b_action, size_t num_steps) { Event* event = m_osystem->event(); // Handle paddles separately: we have to manually update the paddle positions at each step if (m_use_paddles) { // Run emulator forward for 'num_steps' for (size_t t = 0; t < num_steps; t++) { // Update paddle position at every step m_state.applyActionPaddles(event, player_a_action, player_b_action); m_osystem->console().mediaSource().update(); m_settings->step(m_osystem->console().system()); } } else { // In joystick mode we only need to set the action events once m_state.setActionJoysticks(event, player_a_action, player_b_action); for (size_t t = 0; t < num_steps; t++) { m_osystem->console().mediaSource().update(); m_settings->step(m_osystem->console().system()); } } // Parse screen and RAM into their respective data structures processScreen(); processRAM(); }
/* ================== getOption ================= This function reads in the user's desired chose of operation. Calls upon other functions to perform the procedure. Pre pHeader - pointer to HEAD structure Post Return */ void getOption (HEAD* pHeader) { // Local Declarations char command; DATA target; DATA* airport = NULL; int i; // Statements while ((command = menu()) != 'Q') { switch (command) { case 'A': if (addAirport(pHeader)) { while (checkHash(pHeader->pHash) == 1) { pHeader->pHash = upsizeHash(pHeader->pHash); } printf ("\n Succesfully added data.\n\n"); } break; case 'D': printf("Enter the airport code: "); scanf(" %s", target.arpCode); if (deleteHash (pHeader, target)) { while (checkHash(pHeader->pHash) == -1) { pHeader->pHash = downsizeHash(pHeader->pHash); } printf ("\n Succesfully deleted data.\n\n"); } break; case 'F': printf("Enter the airport code: "); scanf(" %s", target.arpCode); // fix sensitive input cases for (i = 0; i < strlen(target.arpCode); i++) { target.arpCode[i] = toupper(target.arpCode[i]); } airport = findHash(pHeader->pHash, &target); if (airport != NULL) { processScreen(airport); } else printf("No airport exists\n"); break; case 'L': printHash(pHeader->pHash); break; case 'K': BST_Traverse(pHeader->pTree, processScreen); break; case 'P': printTree(pHeader->pTree->root, 0); printf("\n"); break; case 'W': outputFile (pHeader->pHash); break; case 'E': efficiency(pHeader->pHash); break; case 'H': pHeader->pHash = hashDemo(pHeader->pHash); break; default: printf("Invalid choice. Choose again\n"); break; } } return; } // getOption