I'm writing a small program in C on Linux and my intentions with it is to do the following:
- Display a menu
- Ask a user to enter a value
- Read the value and run the corresponding command
- Wait for the command to finish before breaking (returning to main menu)
- Repeat until the user enters the value corresponding to "Exit/Quit"
So far, this is the code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("\n\n\t\tListen to music on CLI\n\n\n");
int choice;
while(1)
{
printf("1. Jazz\n");
printf("2. Hip-Hop\n");
printf("3. Pop\n");
printf("4. Exit\n\n\n");
printf("Enter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
system("mpv --no-video https://www.youtube.com/watch?v=GhAbBh3jwpg");
break;
case 2:
//same as case 1
break;
case 3:
//same as case 1
break;
case 4:
printf("\n\n\t\t\tCoding is Fun !\n\n\n");
exit(0); // terminates the complete program execution
}
}
printf("\n\n\t\t\tCoding is Fun !\n\n\n");
return 0;
}
The above code works but with the following issues:
- if you enter 1 (or 2, 3, etc), the program displays the menu again then executes the statement
- once mpv finishes playing the audio the program does not return to the main menu
Those are the two issues I am having so far.
Please see the above statements.