I created a structure of size n & started taking input, but everytime i run it won't take input for name if i use only one gets(). This code only works if I use two gets() both above & below my print statement.
#include <stdio.h>
struct Driver
{
char name[50];
char licence[50];
char route[50];
int kms[6];
};
int main()
{
int n, response;
printf("WELCOME TO MY DRIVING AGENCY\n");
printf("\nEnter the no. of data you want to enter - ");
scanf("%d", &n);
struct Driver a[n];
for(int i = 0; i < n; i++) // Take inputs
{
printf("\nEnter the information for Driver no.%d\n", i+1);
gets(a[i].name);
printf("Enter name - "); // WHY WHENEVER I REMOVE ANY OF THE get(a[i].name) IT WON'T TAKE INPUT FOR name
gets(a[i].name);
printf("Enter licence no. - ");
gets(a[i].licence);
printf("Enter final destination (route) - ");
gets(a[i].route);
printf("Enter distance travelled in kms (Enter no. only) - ");
scanf("%d", &a[i].kms);
}
return 0;
}
Why this code is not working with only one get(a[i].name)