int i=0; // global int for array count through out the program
struct student_data // global struct
{
char name[20];
int roll;
char depart[10];
int course;
int y_o_j;
};
struct student_data stdt[450]; // global struct variable
void main(void)
{
char sel;
int ex;
ex=2;
do
{
printf("\nSelect An Option\n [e]nter data \n [s]how data \n e[x]it\n\n");
scanf("\n%c",&sel);
switch(sel)
{
case 'e':
input();
break;
case 's':
show();
break;
case 'x':
ex=1;
break;
}
}while(ex==1);
}
void input(void)
{
int s,k;
s=k=0;
printf("\nSelect \t [1] One Input [2] Multiple input ");
scanf("\n%d",s);
if(s==1)
{
printf("\n Enter Name : " );
scanf("\n%s",stdt[i].name);
printf("\n Enter Roll No.: ");
scanf("\n%d",&stdt[i].roll);
printf("\n Enter Department Name : ");
scanf ("\n%s",stdt[i].depart);
printf("\n Enter Course No.: ");
scanf("\n%d",&stdt[i].course);
printf("\n Enter Year of Joining: ");
scanf("\n%d",&stdt[i].y_o_j);
i++;
}
if(s==2)
{
printf("\n Enter Limit of Students:");
scanf("%d",k);
while(i==k) // will save untill limit
{
printf("\n Enter Name : " );
scanf("\n%s",stdt[i].name);
printf("\n Enter Roll No.: ");
scanf("\n%d",&stdt[i].roll);
printf("\n Enter Department Name : ");
scanf ("\n%s",stdt[i].depart);
printf("\n Enter Course No.: ");
scanf("%d",&stdt[i].course);
printf("\n Enter Year of Joining: ");
scanf("%d",&stdt[i].y_o_j);
i++; // one address moves further
}
}
}
void show (void) // to show data
{
char opt;
printf("\n Select : \n Show By [Y]ear \n Show By [R]oll No. ");
scanf("%c",&opt);
Please use code tags around your code: [code]code here[/code]
Also, please clearly specify the problem you have, what output are you expecting and what are you getting, if you get any compiler errors, which ones do you get?
That should help us find the problem more efficiently.