Im going through a C tutorial and im going to create a Database as part of the course. Im just in the very beginning of the project so its a very simple program so far.
I was trying to test it out but there seems to various problems with it and im at loss what it could be.
Code:
#include<stdio.h>
main()
{
/*Variabler för att lagra information om skiva*/
char title[200];
char artist[100];
int tracks;
int price;
int albsing;
/*Variabler för menyknappar*/
int menukey;
int storemenukey;
int readmenukey;
/*tillfällig variabel. används i switch case*/
char aob;
/*Huvudmeny med 2 val: Antingen lagra ny skiva eller hämta information om en redan lagrad skiva*/
printf("MAIN MENU\nSelect operation: 1 to store, 2 to read\n");
scanf("%d",&menukey);
switch (menukey)
{
/*Meny för att lagra ny information om skiva. Lämnar default som break tillsvidare*/
case 1:
printf("Select operation: 1.Title 2.Artist 3.Tracklist 4.Price 5.Album/Single\n");
scanf("%d",storemenukey);
switch (storemenukey)
{
case 1:
printf("Enter album title:\n");
scanf("%s",title);
break;
case 2:
printf("Enter artist name:\n");
scanf("%s",artist);
break;
case 3:
printf("Enter number of tracks on the record:\n");
scanf("%d",&tracks);
break;
case 4:
printf("Enter price:\n");
scanf("%d",&price);
break;
case 5:
/*Sätter albsing till 1 om album och 0 om singel*/
printf("Is this record A - an album or B - a single. Choose A or B:\n");
scanf("%c",&aob);
if (strcmp(aob,"A") == 0)
albsing = 1;
else if (strcmp(aob,"B") == 0)
albsing = 0;
else
break;
default:
break;
}
break;
/*Meny för att hämta information om skiva*/
case 2:
printf("Select operation: 1.Title 2.Artist 3.Tracklist 4.Price 5.Album/Single\n");
scanf("%d",readmenukey);
switch (readmenukey)
{
case 1:
printf("%s\n",title);
break;
case 2:
printf("%s\n",artist);
break;
case 3:
printf("%d\n",tracks);
break;
case 4:
printf("%d\n",price);
break;
case 5:
if (aob == 0)
printf("Single\n");
else
printf("Album\n");
break;
default:
break;
}
break;
default:
break;
}
}
The first switch case statement takes me to the menu of choice, 1 or 2. However, chosing menu option one and trying to input a title or artist name, the program crashes.
Next, going into menu option 2 and then trying to print out, for example, title nothing happends. The process just ends.
Again, im sure this simple prototype is full of errors so i figured id turn to you guys for help.
Thanks in advance!