//toverify:-1st enter 1 then enter1 then add the info...now enter 2 you will get the error???please ans
Code:
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include <stdlib.h>
#include<string.h>

void student_db();
void disp_info();
void edit_info();

struct s_database
{
    char s_name[10];
    char s_ph_number[10];
    char s_ID_number[10];
}database[10];

int main()
{
    char num;
    while(1)
    {

    printf("Enter 1-> To create New Student\nEnter 2-> To Display Information of all students\nEnter 3-> To Edit Students Info\n");
    fflush(stdin);
    scanf("%d",&num);
    //num=0;          //num=0 should be initialized here because if not than switch will be executed twice.
    switch(num)
    {
        case 1:
        {
            student_db();
            break;
        }
        case 2:
        {
            disp_info();
            break;
        }
        case 3:
        {
            edit_info();
            break;
        }
        case 4:
        {
            exit(1);;
        }
        default:
        {
            printf("Invalid number entered...please select 1,2 or 3\n");
          //  num=0;          //num=0 should be initialized here because if not than switch will be executed twice.
            break;
            getch();
        }
    }
    }
    //getch();
    return 0;
}
void student_db()
{
    char no=0;
    int i=1;
    printf("--------------------------------------------------------------------------------\n");
    printf("Enter the number of students information you will be adding to the database\n");
    fflush(stdin);
    scanf("%d",&no);
    printf("--------------------------------------------------------------------------------\n");
    if(no>0)
    {
        printf("Enter students name\t\tcontact number\t\tID_number\n");
    while(no!=0)
    {
        printf("Enter student[%d]  Information\n",i);
        fflush(stdin);
        gets(database[no].s_name);
        fflush(stdin);
        gets(database[no].s_ph_number);
        fflush(stdin);
        gets(database[no].s_ID_number);
       // fflush(stdin);
        no--;
        i++;
    }
    printf("Student Info saved \n");
    getch();

    //student_db();
    }
    else
    {
        printf("Invalid number entered...\n");
        //goto step1;
        student_db();
    }
}
void disp_info()
{
    int no;
    for(no=0;no<10;no++)
    {
    puts(database[no].s_name);
    puts(database[no].s_ph_number);
    puts(database[no].s_ID_number);
    }
}
void edit_info()
{
    char name[10],no;
    printf("enter the students name to edit his database\n");
    //getch();
    fflush(stdin);
    gets(name);

    for(no=0;no<10;no++)
    {
    if(!(strcmp(database[no].s_name,name)))
    {
        printf("Enter students name\t contact number\t and ID_number\n");
        gets(database[no].s_name);
        gets(database[no].s_ph_number);
        gets(database[no].s_ID_number);
    }
    }
    printf("entered name is not in the student database list\n");
}

Last edited by shabbir; 17Feb2010 at 09:55.. Reason: Code blocks