The logic of the program is quite clear but when it asks the user to enter name. The second time it asks for the name i.e at i=1 it asks for the name and also asks for the year to be entered. In short its not allowing to the user to enter data after i=0 in int year.
/* Write a program to take input name roll number and year of joining of 5 students and making a function which prints name of only those who have joined in the particular year mentioned by the user*/
#include<stdio.h>
#include<conio.h>
struct student
{
   char name[50];
   int year;
}
a[5];
void func ( void );
void main ( void )
{
   int i;
   for ( i = 0; i < 5; i++ )
   {
      printf ( "Enter name %d\n", i + 1 );
      gets ( a[i].name );
      puts ( "Enter year" );
      scanf ( "%d", &a[i].year );
   }
   func(); 
   getch();
}
void func ( void )
{
   int i;
   int yearr;
   printf ( "Enter a year:" );
   scanf ( "%d", &yearr );
   for ( i = 0; i < 5; i++ )
   {
      if ( yearr == a[i].year )
      {
         printf ( "%s", a[i].name );
      }// if ends
   }//for ends
}// func ends
 
     
     
     
    