Thread: switch satement

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    8

    Question switch satement

    i have to do this program that reads 15 employee records into a 20 element array, and that your able to search , add, remove, print , and exit . I have tired reading the tutorials and in my book but still very lost. This is a part of the program that has the switch statment. If anyone can help me out please.. it would be greatly appreciated

    Code:
    int main()
    
    {
    
    student_record database[SIZE]; //database for student records
    
    char command; //holds the command to execute
    
    int count=0; //contains count of actual number of items in database
    
    initialize(database,count);
    
    printf("Enter a command: s=search, p=print, r=remove,i=insert, e=exit\n");
    
    scanf(" %c", &command);
    
    
    {
    while (command!='e')
    
    
    
    switch (command)
    
    
    
    case 's' :search(student_record DB[], int count, char key[]) ;
    break;
    
    case 'p' : print_array(int x[ ], int count);
    break;
    
    case 'r': remove_record(student_record DB[], int * count, char key[]);
    break;
    
    case 'i': insert(student_record DB[], int * count);
    break;
    }
    
    
    printf("Enter acommand:s=search,p=print,r=remove,i=insert,e=exit\n");
    
    scanf(" &c", &command);
    
    
    
    return 0;
    
    }

  2. #2
    * noops's Avatar
    Join Date
    Jun 2008
    Posts
    108
    It would help if you could state what problem you are encountering.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > search(student_record DB[], int count, char key[]) ;
    Well you managed to call functions outside of case statements, so why did you just paste the prototypes inside?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Code:
    {
    while (command!='e')
    
    
    
    switch (command)
    
    
    
    case 's' :search(student_record DB[], int count, char key[]) ;
    break;
    
    case 'p' : print_array(int x[ ], int count);
    break;
    
    case 'r': remove_record(student_record DB[], int * count, char key[]);
    break;
    
    case 'i': insert(student_record DB[], int * count);
    break;
    }
    What are those braces meant to be doing?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  3. Switch
    By cogeek in forum C Programming
    Replies: 4
    Last Post: 12-23-2004, 06:40 PM
  4. Switch Case
    By FromHolland in forum C++ Programming
    Replies: 7
    Last Post: 06-13-2003, 03:51 AM