• + 0 comments

    The problem is not clear about implementation.

    Here is my explanation.

    // For this, before `while` loop, you need to initialize dynamic arrays (which are declared on top of the main) to store numbers of:
    // - total_number_of_books
    // - total_number_of_pages
    
    // x y : (a) Insert a book (b) with y pages (c) at the end of the x^th shelf.
    
    // (a) Insert a book
    total_number_of_books[x] += 1;  
    // *(total_number_of_books + x) += 1; // the same - equivalent in old books/tutorials
    
    // (b) allocate memory (int) for the new shelf: ( void *ptr, size_t new_size );
    // - total_number_of_pages just get bigger by int as we inserted a book
    
    // (c) assign number of pages [y] to the x^th shelf
    

    Simpler, isn't it?