This is a program to store details of an employee in a structure. Although the program runs it shows many errors, it does not give me a chance to enter address. Why is the program not running properly . Where am I going wrong ?
#include <stdio.h>
#include <conio.h>
struct details
{
char name[30];
int age;
char address[500];
float salary;
};
int main()
{
struct details detail;
clrscr();
printf("\nEnter name:\n");
gets(detail.name);
printf("\nEnter age:\n");
scanf("%d",&detail.age);
printf("\nEnter Address:\n");
gets(detail.address);
printf("\nEnter Salary:\n");
scanf("%f",&detail.salary);
printf("\n\n\n");
printf("Name of the Employee : %s \n",detail.name);
printf("Age of the Employee : %d \n",detail.age);
printf("Address of the Employee : %s \n",detail.address);
printf("Salary of the Employee : %f \n",detail.salary);
getch();
}
This is the output I get:

Statement
scanf("%d",&detail.age);will read222but not the newline you’ve entered. This newline will remain in input buffer and pass it to next input gets().You can use
getchar()method to remove some chars from the input buffer to avoid such problems.Another problem is the incorrect use of format specifier with
printffunction.