SPECIAL NOTE: This lab is a part of a series 2.4.1.5 Songs List -> 2.4.2.6 Make Songs -> 2.4.2.6 filter songs. You must first complete 2.4.2.6 Filter Songs before you can start on this lab.
Objective
In this lab, we will create a new version of the song list program where the results are filtered and paginated.
Requirements
- Create paging for full list
- Declare a starting index variable
- Wrap the printing for loop in an while that terminates when the user inputs a 'q'
- Change the for loop that prints songs so that it only display 10 songs
- Below the for loop, add a user input prompt
printf("(n for next, p for prev, f for filter, q for quit): ");
- Get the user's choice
- if next then increase starting index by 10 as long as it will not exceed the last song's index
- if prev then decrease starting index by 10 as long as it will not make it go below 0
- Add filtered pagination
- Once the list is filtered, it breaks the next and previous functionality.
- moving to next, requires the code to know when a song is being displayed and keeping track of the number of songs displayed
- To solve this problem, the program will implement a stack that stores the last starting index
- Pushes the current starting index onto the stack when the user chooses next and then increments it
- Pops the top most (last pushed) index when the user choose previous and uses it as the starting index
- The function should not repeat entries (e.g., at the end of the list it shold not keep adding the last starting index)
- If the stack is empty it should set the starting index to 0
Steps to Complete
- Implement the requirements
- Compile and test the program
- Run /challenge/tester
- Get flag
Connect with SSH
Link your
SSH key, then connect with:
ssh hacker@pwn.college