0

The code works fine in first iteration but in second iteration the player_name is not asking for input it jumps directly to second fgets. And the puts prints a extra line space after it

#include<stdio.h>
#include<string.h>
struct cricket
{
char player_name[20];
char team_name[30];
float average;
}cricket;
void main()
{
for(int i=1;i<=5;i++)
{printf("Enter the detail of team %d\n",i);
printf("Enter the player name :");
fgets(cricket.player_name, 20, stdin);
printf("Enter the team name :");
fgets(cricket.team_name, 30, stdin);
printf("Enter the batting average of the player :");
scanf(" %f",&cricket.average);
puts(cricket.player_name);
puts(cricket.team_name);
printf("%f\n",cricket.average);
}
}

0 Answers0