Results 1 to 3 of 3

Thread: Can anyone help me with this C code?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member dj.turkmaster's Avatar
    Join Date
    Feb 2007
    Location
    TURKEY/Ankara
    Posts
    139

    Default Can anyone help me with this C code?

    Hello, I am computer science student in a university in Turkey. Well I need a little help with the code below.
    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(); //Skip this line
    void search_dvd(); //Skip this line
    void list_dvd(); //Skip this line
    void edit_dvd(); //Skip this line
    void hire_dvd(); //Skip this line
    void quit(); //Skip this line
    
    
    
    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);
    }	
    
    //The problem starts here
    
    printf("Please enter the name of the dvd:");
    gets(dvd[serial].name);    // It doesn't get the name =(
    printf("\nPlease enter the price of the dvd:");
    scanf("%d", &dvd[serial].price);    // It gets the price, no problem
    printf("Please enter the director of the dvd:");
    gets(dvd[serial].director);  // It doesn't get the dircetor here =((
    printf("\nPlease enter the genre of the dvd:");
    gets(dvd[serial].genre);   // It gets the genre, no problem
    printf("%d\n", dvd[serial].price); //These lines also works
    puts(dvd[serial].genre);
    }
    Any idea why it doesn't get the director name and the name of the dvd?
    Last edited by dj.turkmaster; 2008-12-15 at 21:44.
    DOCTUS.ORG Turkish security forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •