Beispiel #1
0
int fold_duplicates_buf::overflow(int c)
{
    if(c == EOF)
        return 0;

    m_buffer += c;

    if(c == '\n')
    {
        if(m_buffer == m_last_buffer)
        {
            m_duplicate_count++;
        }
        else
        {
            if(!print_duplicates())
                return EOF;

            if(m_streambuf->sputn(m_buffer.c_str(), m_buffer.size()) != (std::streamsize) m_buffer.size())
                return EOF;

            m_last_buffer = m_buffer;
        }

        m_buffer.erase();
    }

    return c;
}
/**
 * Run the navigational loop
 *
 * @return Number on exit. 0 for no errors.
 */
int Run()
{
    int sel;
    int arr_length = 0;
    Car ** car_array = (Car **) malloc(10 * sizeof(struct Car *));

    // While true
    while(true) {

        // Print the menu and get a selection
        sel = PrintMenu();

        // Next step depends on the selection made
        switch(sel) {

            // User chose 1
            case 1:
                printf("You selected \"Print the cars array\"\n\n");
                print_cars_array(car_array, &arr_length);
                break;

            // User chose 2
            case 2:
                printf("You selected \"Insert the car records into a sorted array\"\n\n");
                insert_sorted_array(car_array, &arr_length);
                break;

            // User chose 3
            case 3:
                printf("You selected \"Sort cars by year\"\n\n");
                sort_cars_by_year(car_array, &arr_length);

                break;

            // User chose 4
            case 4:
                printf("You selected \"Print duplicates\"\n\n");
                print_duplicates(car_array, &arr_length);
                break;

            // User chose 5
            case 5:
                printf("You selected \"Exit\"\n\n");

                // Return here, with no erros, to exit the function.
                // Clean up will be next
                return 0;

            // User chose soomething not on the menu
            default:
                printf("Please enter a valid number from the menu!\n\n");
                break;
        }

    printf("--------------------\n");

    }
}
Beispiel #3
0
fold_duplicates_buf::~fold_duplicates_buf()
{
    // Flush any leftover output ...
    print_duplicates();

    if(m_buffer.size())
        m_streambuf->sputn(m_buffer.c_str(), m_buffer.size());

    m_stream.rdbuf(m_streambuf);
}