#include<stdio.h>
#include<string.h>
struct employee{
int salary;
int code;
char name[50];
};
int main(){
struct employee e1,e2;
printf("enter the credentials of e1 name\n");
gets(e1.name);
printf("enter the code \n");
scanf("%d",&e1.code);
printf("enter the salary \n");
scanf("%d",&e1.salary);
printf("enter the credentials of e2 name \n");
gets(e2.name);// scanf("%s",e2.name); works but not gets see output
printf("enter the code \n");
scanf("%d",&e2.code);
printf("enter the salary \n");
scanf("%d",&e2.salary);
printf("***************************************************************************************");
printf("e1 credentials\n");
printf("name is %s\n",e1.name);
printf("code is %d\n",e1.code);
printf("salary is %d\n",e1.salary);
printf("e2 credentials\n");
printf("name is %s\n",e1.name);
printf("code is %d\n",e1.code);
printf("salary is %d\n",e1.salary);
return 0;
}
output
enter the credentials of e1 name
harry
enter the code
648
enter the salary
384
enter the credentials of e2 name
enter the code
46
enter the salary
4
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*e1 credentials
name is harry
code is 648
salary is 384
e2 credentials
name is harry
code is 648
salary is 384
I thought that it should work for e2.name but it is not why??