So, this was my project:
You manage a travel agency and you want your n drivers to input their following details:
- Name
- Driving License No
- Route
- Kms
- Your program should be able to take n as input(or you can take n=3 for simplicity) and your drivers will start inputting their details one by one.
Your program should print details of the drivers in a beautiful fashion. User structures.
Here is my solution:
#include <stdio.h>
 struct driver_details
{
    char name[50];
    char licence_no[25];
    char route[20];
    char kms[5];
};
void displayDetails(struct driver_details arr)
{
    printf("\t1. Name of the driver: %s\n",arr.name);
    printf("\t2. Driving License Number: %s\n",arr.licence_no);
    printf("\t3. Route followed: %s\n",arr.route);
    printf("\t4. Total Kilometers travelled: %s\n",arr.kms);
}
int main()
{
    int n;
    printf("Enter the number of drivers:\n");
    scanf("%d",&n);
    struct driver_details arr[n];
   
    for (int i = 0; i < n; ++i)
    {
        printf("Enter the detail of driver number: %d\n",(i+1));
        printf("Enter your name:\n");
        gets(arr[i].name);
        printf("Enter your driving license number:\n");
        gets(arr[i].licence_no);
        printf("Enter your route:\n");
        gets(arr[i].route);
        printf("Enter the kilometers travelled:\n");
        gets(arr[i].kms);
        printf("\n");
    }
    for (int i = 0; i < n; ++i)
    {
        printf("The details of the driver %s:\n",arr[i].name);
        displayDetails(arr[i]);
    }
    return 0;
}
I was expecting it to take the user details one by one and then print them accordingly. But, when I ran my program, this was observed:
Enter the number of drivers:
1
Enter the detail of driver number: 1
Enter your name:
Enter your driving license number:
User
Enter your route:
xyz-abd
Enter the kilometers travelled:
2345
The details of the driver :
        1. Name of the driver:
        2. Driving License Number: User
        3. Route followed: xyz-abd
        4. Total Kilometers travelled: 2345
As shown, it totally skips the name attribute and I have tried various methods but they didn't work. What should I do?
P.S : I am not that well-versed in structures
 
     
    