-3

My code is supposed to take the basic info of 'n' number of drivers, and print it in a nice manner. I have to use structure, but idk why it isn't recognizing driveri.name, and other elements of structure while printing the data, it is showing 'driveri.name undeclared'. NOTE: I've just learnt structures in c, and don't know anything about dynamic memory allocation.

struct manager
{
    char name[50];
    int dln;
    char route[100];
    float kms;
};
int main()
{
    int n;
    printf("Enter the number of drivers\n");
    char d;
    scanf("%d%c",&n, &d);
    for (int i=1;i<=n;i++)
    {
        struct manager drivieri;
        char arr1[50];
        printf("\nEnter the name of driver %d\n",i);
        gets(arr1);
        strcpy(driveri.name, arr1);
        printf("\n\n* * * * * * *\n");
        printf("The name of Driver %d is: %s",i,driveri.name);
        printf("\n* * * * * * *\n\n");
        int a;
        printf("\nEnter the Driving license number of driver %d\n",i);
        scanf("%d",&a);
        driveri.dln=a;
        printf("\n\n* * * * * * *\n");
        printf("The driving license number of Driver %d is: %d",i,driveri.dln);
        printf("\n* * * * * * *\n\n");
        char arr2[100];
        printf("\nEnter the route of driver %d\n",i);
        gets(arr2);
        strcpy(driveri.route, arr2);
        printf("\n* * * * * * *\n");
        printf("The route of Driver %d is: %s",i,driveri.route);
        printf("\n* * * * * * *\n\n");
        float b;
        printf("\nEnter the number of kilometers, driver %d have driven\n",i);
        scanf("%f", &b);
        driveri.kms=b;
        printf("\n* * * * * * *\n");
        printf("The Driver %d have driven %f kms.",i,driveri.kms);
        printf("\n* * * * * * *\n");
    }
    return 0;
}
Tauqeer
  • 15
  • 3
  • 2
    drivieri is different than driveri. Gotta watch that spelling. – Avi Berger Aug 23 '22 at 05:27
  • 1
    Note, you don't need the intermediate variables, and [`gets()` should not be used](https://stackoverflow.com/q/1694036/1270789). – Ken Y-N Aug 23 '22 at 05:32
  • DID I JUST ASKED A QUES. ON STACKOVERFLOW JUST BCZ. OF A VERY STUPID SPELLING MISTAKE WHICH I OVERLOOKED BCZ. I THOUGHT I AM NOT GOOD IN STRUCTURES THAT'S WHY THE STRUCTURE MIGHT BE HAVING SOME MISTAKE. – Tauqeer Aug 23 '22 at 05:46

1 Answers1

2

Did you try compiling?

Line 22:16: ‘driveri’ undeclared 

So, the declaration is of drivieri but you've used as driveri

Just change the declaration and it should work.

Ani
  • 1,448
  • 1
  • 16
  • 38