here is the code which is working fool proof...but when i try to display info saved by pressing 3 and enter wrong students name im getting
printf("entered name is not in the student database list\n");
it 10 times...help me in reducing it to only one time
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()
{

    while(1)
    {
    static char num;

    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()
{
    int no;
    int i=1;
    int j=0;
    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!=1)&&(no!=2)&&(no!=3))
    {
        printf("Invalid number entered...\n");
        //goto step1;
        student_db();
    }
    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[j].s_name);      //insted of j if i put no..it will be an error..which leads to 2,1,0 arrayfeed
        fflush(stdin);
        gets(database[j].s_ph_number);
        fflush(stdin);
        gets(database[j].s_ID_number);
       // fflush(stdin);
        --no;
        ++i;
        ++j;
    }
    printf("Student Info saved \n");
    printf("--------------------------------------------------------------------------------\n");
    //getch();

    //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("Student Info saved \n");
    }
    else
    {
        printf("entered name is not in the student database list\n");
    }
    }

}

Last edited by shabbir; 17Feb2010 at 23:36.. Reason: Code blocks