I have to make an array of structure for cricketers presenting their name, age etc. and take input of each value from user . I am trying to get value of name from the user but my code editor keeps on skipping that line i have tried gets , scanf with %s , scanf with %[^n]s and fgets nothing works the whole line gets skipped . I want to take full name as input.
#include<stdio.h>
#include<string.h>
#define name_len 20
int main (){
printf("enter no of players :");
int n;
scanf("%d",&n);
typedef struct cricketers {
char name[name_len];
int age;
int testMatches;
float avgRuns;
} players;
players arr[n];
for (int i = 0; i < n; i++)
{
printf("enter name of the player indexed %d",i);
fgets(arr[i].name,name_len,stdin);
printf("enter age of the player indexed %d",i);
scanf("%d",&arr[i].age);
printf("enter no of test matches played by the player indexed %d",i);
scanf("%d",&arr[i].testMatches);
printf("enter avg runs in each test math of the player indexed %d",i);
scanf("%f",&arr[i].avgRuns);
}
return 0;
}
pliz help ????????
i already tried this and that fgets func too
gets(arr[i].name);
scanf("%s",arr[i].name);
scanf("%[^n]s",arr[i].name);
scanf("%[^n]",arr[i].name);
New contributor