Write a program to create a structure employee with empno, name and salary, accept and display the details with ordinary and pointer structure variable.
/* Write a program to create a structure employee with empno, name and salary,
accept and
display the details with ordinary and pointer structure variable.*/
#include
<stdio.h>
struct
employee
{
int empno;
char empname[20];
float sal;
}e1,e2,*p;
void main()
{
p=&e2;
printf("Employee 1:\n");
printf("Enter the employee number :
");
scanf("%d",&e1.empno);
fflush(stdin);
printf("Enter the employee name : ");
gets(e1.empname);
printf("Enter the employee salary :
");
scanf("%f",&e1.sal);
printf("Employee 2:\n");
printf("Enter the employee number :
");
scanf("%d",&p->empno);
fflush(stdin);
printf("Enter the employee name : ");
gets(p->empname);
printf("Enter the employee salary :
");
scanf("%f",&p->sal);
printf("--------------------------------------------------------------\n");
printf(" Empno
Employee Name
Salary\n");
printf("--------------------------------------------------------------\n");
printf(" %5d
%-26s
%7.2f\n",e1.empno,e1.empname,e1.sal);
printf(" %5d
%-26s
%7.2f\n",p->empno,p->empname,p->sal);
printf("--------------------------------------------------------------\n");
getch();
}
Comments
Post a Comment