Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 925613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:32:53+00:00 2026-05-15T19:32:53+00:00

The logic of the program is quite clear but when it asks the user

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:32:54+00:00Added an answer on May 15, 2026 at 7:32 pm

    Clear the input buffer before taking input using fflush(stdin) or fflushall(). Your modified code is given below.

    /* 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 );
              fflush(stdin);
              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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is may be not program question, but i guess its program logic question.
I have some logic, which defines and uses some user-defined types, like these: class
I am getting confused between domain/application logic and User Interface logic. To illustrate what
I'm writing a simple time tracking program to manage my own projects. I'm a
I've used BackgroundWorkers quite a bit, but I've never experienced this problem before. My
I have two files. main.py that has main program logic and functions.py that has
Suppose I develop an application with the logic as a CLI program that can
When you're writing a program that consists of a small bit of main logic
What would be the best way of separating program logic to the GUI code?
I've worked on quite a few WPF solutions, and this is the first time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.