Error While Input function

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>


#define ERROR printf("\ninvalid input\n\n");

void show (void);
void input (void);
void showyear(void);
void showroll (void);



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);

if(opt=='y' || opt=='Y')
showyear();
if(opt=='r' || opt=='R')
showroll();
else
ERROR
}




void showyear(void) // show by year

{
int year,c;
printf("\n Enter Year Of Enrollment: ");
scanf("%d",year);

for (c=0; c<=i; c++)
{
if(stdt[c].y_o_j==year)
printf("%s",stdt[c].name);
}


}




void showroll (void) // show by roll no.
{
int roll,c;
printf("\n Enter Roll Number: ");
scanf("%d",roll);

for (c=0; c<=i; c++)
{
if(stdt[c].roll==roll)
{


printf("Name: %s",stdt[c].name);
printf("Department: %s",stdt[c].depart);
printf("Course No.: %d",stdt[c].course);
printf("Roll No.: %d",stdt[c].roll);
printf("Year of Joining: %d",stdt[c].y_o_j);
}

}

}
Last edited on
closed account (o3hC5Di1)
Hi there,

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.

Thanks.

All the best,
NwN
Topic archived. No new replies allowed.