I have written a c program to create a structure containing the name of cricketer (char array), his age (integer), and number of test matches (integer) that he has played and the average runs (float) that he has scored in each test match. while writing the input for the same when in for loop(for the input) value gets greater or equal to 2 it does take the input for the name(i.e %s).
//Write a C program to create a record containing the name of cricketer (char array), his age
//(integer), and number of test matches (integer) that he has played and the average runs
//(float) that he has scored in each test match. Create an array of structures to hold records
//of 20 such cricketers and then write a program to read these records and print it, also find
//the cricketer which has the highest average.
#include<stdio.h>
struct cricketer
{
char name[40];
int age;
int match;
float run;
};
int main()
{
struct cricketer player[20];
for(int i=0;i<3;i++)
{
printf("Enter the information of %d cricketer\n",i+1);
printf("Enter name \n");
scanf("%[^\n]s",&player[i].name);
printf("Enter age\n");
scanf("%d",&player[i].age);
printf("Enter number of matches played\n");
scanf("%d",&player[i].match);
printf("Enter average\n");
scanf("%d",&player[i].run);
}
for(int i=0;i<3;i++)
{
printf("Name:%s\nage:%d\nNumber of matches:%d\nAverage:%f\n",player[i].name,player[i].age,player[i].match,player[i].run);
}
float high=player[0].run;
for(int i=0;i<3;i++)
{
if(high<player[i].run)
{
player[i].run=high;
}
}
printf("The higgest Average is %f",high);
return 0;
}
help me in knowing the the reason behind the problem of not taking an input explanation and correction for the same.