123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
#include <stdio.h> #include <stdlib.h> #define COMPANY_NUM_EMPL 6 #define NAME_LENGTH 20 typedef struct { char first_name[20]; char last_name[20]; int years_of_empl; float salary; }Employee; /*typedef struct { Employee *empl; }Company; */ int main(){ int i; Employee *empl=calloc(COMPANY_NUM_EMPL,sizeof(*empl)); /*for (i=0;i<COMPANY_NUM_EMPL;i++){ empl[i].first_name=calloc(NAME_LENGTH,sizeof(char)); empl[i].last_name=calloc(NAME_LENGTH,sizeof(char)); }*/ for (i=0;i<COMPANY_NUM_EMPL;i++){ printf("Enter First Name\n"); scanf("%s",empl[i].first_name); printf("%s\n",empl[i].first_name); printf("Enter Last Name\n"); scanf("%s",empl[i].last_name); printf("Enter Years of Employment\n"); scanf("%d",empl[i].years_of_empl); printf("Enter Salary\n"); scanf("%f",empl[i].salary); printf("%s\n%s\n%d\n%f",empl[i].first_name, empl[i].last_name, empl[i].years_of_empl, empl[i].salary); } return 0; }
Employee *empl = (Employee*)calloc(COMPANY_NUM_EMPL,sizeof(*empl));