Hello, I am computer science student in a university in Turkey. Well I need a little help with the code below.
Any idea why it doesn't get the director name and the name of the dvd?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct dvd_type{
int price;
char name[21];
char genre[9];
char director[19];
char state[5];
} dvd[500];
void add_dvd(struct dvd_type[]);
void remove_dvd(); [COLOR="Green"]//Skip this line[/COLOR]
void search_dvd(); [COLOR="Green"]//Skip this line[/COLOR]
void list_dvd(); [COLOR="Green"]//Skip this line[/COLOR]
void edit_dvd(); [COLOR="Green"]//Skip this line[/COLOR]
void hire_dvd(); [COLOR="Green"]//Skip this line[/COLOR]
void quit(); [COLOR="Green"]//Skip this line[/COLOR]
int main() {
struct dvd_type dvd[500];
char choice;
printf(" ---HUBM DVD--- \nA: Add new dvd\nR: Remove dvd\nS: Search dvd\nL: List dvd\nE: Edit dvd\nH: Hire dvd\nQ: Quit\nEnter command:");
scanf("%c", &choice);
if (choice == 'A'){
add_dvd(dvd);
}/*
else if (choice == 'R'){
remove_dvd();
}
else if (choice == 'S'){
search_dvd();
}
else if (choice == 'L'){
list_dvd();
}
else if (choice == 'E'){
edit_dvd();
}
else if (choice == 'H'){
hire_dvd();
}
else if (choice == 'Q'){
quit();
}*/
else {
printf("ERROR! Please enter one of these letters: A R S L E H Q");
}
return 0;
}
void add_dvd(struct dvd_type dvd[]){
int serial;
printf("Please enter the serial number of the dvd you want to add.\nSerial:");
scanf("%d", &serial);
while (serial>500 & serial<=0){
printf("The serial should be between 1 and 500. Please enter a new serial");
scanf("%d", &serial);
}
[COLOR="Green"][B]//The problem starts here[/B][/COLOR]
printf("Please enter the name of the dvd:");
gets(dvd[serial].name); [COLOR="Green"] // It doesn't get the name =([/COLOR]
printf("\nPlease enter the price of the dvd:");
scanf("%d", &dvd[serial].price); [COLOR="Green"] // It gets the price, no problem[/COLOR]
printf("Please enter the director of the dvd:");
gets(dvd[serial].director); [COLOR="Green"] // It doesn't get the dircetor here =(([/COLOR]
printf("\nPlease enter the genre of the dvd:");
gets(dvd[serial].genre); [COLOR="Green"] // It gets the genre, no problem[/COLOR]
printf("%d\n", dvd[serial].price);[COLOR="Green"] //These lines also works[/COLOR]
puts(dvd[serial].genre);
}
Any idea why it doesn't get the director name and the name of the dvd?
Last edited: