Structure in C

Why am I not getting the right display in C?
[code]
<#include<stdio.h>
#include<conio.h>
struct boat
{ int age;
char name[30];
}passengerinfo[2];
void main()
{ clrscr();
int a;
printf("\nEnter the number of tickets:");
scanf("%d",&a);
for(int i=0;i<a;i++)
{ printf("\nEnter name[%d]:",i+1);
scanf("%s",&passengerinfo[i].name);
printf("\nEnter age[%d]:",i+1);
scanf("%s",&passengerinfo[i].age);
}
printf("\nThe boarders of the boats:");
for(i=0;i<a;i++)
{ printf("\nName:%s",passengerinfo[i].name);
printf("\tAge:%d",passengerinfo[i].age);
}
getch();
}>
[\code]

I am able to type the name and age but my output comes as:

Name: Age:
Name: Age:

which is not what I want.Nothing is printed against the Name and Age.Please help me.Thanks.
Last edited on
change
scanf("%s",&passengerinfo[i].name); // Wrong &
to
scanf("%s",passengerinfo[i].name); // Note: no &

change
scanf("%s",&passengerinfo[i].age);// Wrong s
to
scanf("%d",&passengerinfo[i].age); // Note: d instead of s
Thanks for your reply. What a shame on me. I changed only the %s to %d in age and everything worked fine. There is no necessity to change &. Thanks.
Topic archived. No new replies allowed.