Esempio n. 1
0
int main (void){
    
    
    // Checks users input and exectutes task based on selection
    int choice = 0;
    
    // As long as user hasnt quit
    while (choice != QUIT)
    {
        // Prints menu, prompts user for selection
        choice = get_menu_choice();
        
        if (choice == 1)
            printf("\nBeeping the computer \a\a\a");
        else{
            if (choice == 2)
                print_report();
        }
    }
    printf("You chose to quit!\n");
    
    return 0;
    
    
}
Esempio n. 2
0
int main(void)
{
  int choice;

  choice = get_menu_choice();

  printf("You chose Menu Option %d\n", choice );

  return 0;
}
Esempio n. 3
0
int main(int argc, char ** argv)
{
    if ( argc != 2 ) {
        fprintf(stderr, "Usage: pricelist FILENAME\n");
        return EXIT_FAILURE;
    }

    const int dbfd = x_open(argv[1], O_RDWR | O_CREAT, 0644);

    bool should_quit = false;

    while ( !should_quit ) {
        print_summary(dbfd, argv[1]);
        int choice = get_menu_choice();

        struct record record;

        switch ( choice ) {
            case MENU_LIST:
                list_records(dbfd);
                break;

            case MENU_ADD:
                get_new_record(&record);
                write_record(dbfd, &record, -1);
                break;

            case MENU_DELETE:
                printf("Enter record number to delete: ");
                fflush(stdout);
                delete_record(dbfd, get_integer());
                break;

            case MENU_QUIT:
                printf("Goodbye!\n");
                should_quit = true;
                break;

            default:
                printf("Invalid menu choice. Try again.\n\n");
                break;
        }
    }

    x_close(dbfd);

    return 0;
}
Esempio n. 4
0
int main(int argc, char *argv[]) 
{
	system("color f4");
	int choice,x=0;
	do{
		choice=get_menu_choice();
		printf("You Chose Menu Option : %d",choice);
		if(choice==4)
		{
			system("color 4f");
			printf("\nbye");
			x=1;
		}	
	
	}while(x!=1);
}
int main(int argc, char *argv[]) {
    menu_options current_option;
    cdc_entry current_cdc_entry;
    int command_result;

    // this block provides a command line api via `command_mode`
    if (argc > 1) {
        command_result = command_mode(argc, argv);
        exit(command_result);
    }

    // if we get here, then we are in interactive mode....
    //    start with an announcement message
    announce();

    // initialize the db. Using 0 here means open an exiting db (actually it
    // will create one, but it won't delete old data for you). To clear the
    // dbs and initialize a new one, use cmd line mode with -i.
    if (!database_initialize(0)) {
        fprintf(stderr, "Sorry, unable to initialize database\n");
        fprintf(stderr, "To create a new database use %s -i\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    // loop over an interactive console menu
    //    the semantics are kind of similar to the ch6 menu, where there's
    //    an "active" cd, and the operations you can do affect that cd

    while(current_option != mo_exit) {
        current_option = get_menu_choice(&current_cdc_entry);
        switch(current_option) {
            case mo_add_cat:
                // add a new catalog item. Lots of error checking here.
                if (enter_new_cat_entry(&current_cdc_entry)) {
                    if (!add_cdc_entry(current_cdc_entry)) {
                        // print message, but also make sure to zero out data
                        fprintf(stderr, "Failed to add new entry\n");
                        memset(&current_cdc_entry, '\0',
                               sizeof(current_cdc_entry));
                    }
                }
                break;
            case mo_add_tracks:
                enter_new_track_entries(&current_cdc_entry);
                break;
            case mo_del_cat:
                del_cat_entry(&current_cdc_entry);
                break;
            case mo_find_cat:
                current_cdc_entry = find_cat();
                break;
            case mo_list_cat_tracks:
                list_tracks(&current_cdc_entry);
                break;
            case mo_del_tracks:
                del_track_entries(&current_cdc_entry);
                break;
            case mo_count_entries:
                count_all_entries();
                break;
            case mo_exit:
            case mo_invalid:
            default:
                // in all three cases, do nothing
                break;
        }
    }

    // close db and exit
    database_close();
    exit(EXIT_SUCCESS);
} // end of main