I'm having trouble in getting the correct output for a program where I have an array of struct with details of employees. I have to print the details entered in the main function, in another function printEmployees with the prototype "void printEmployees (employee emp[NUM_EMP], int c)". Could someone please let me know what's going wrong? Since instead of the information I've entered it's printing out random characters and symbols. Here's the code-
#include <stdio.h>
#include <stdlib.h>
#define SIZE 25
#define NUM_EMP 3
typedef struct Employees
{
char fname[20];
char lname[20];
int id;
char dependents [3][20];
}employee;
int main()
{
employee emp[3];
printf("Enter %d Employee details-\n", NUM_EMP);
int i;
for (i=0;i<NUM_EMP; i++)
{
printf("Enter %d employee first name-",i+1);
gets(emp[i].fname);
printf("Enter %d employee last name-", i+1);
gets(emp[i].lname);
printf("Enter %d employee id-",i+1);
scanf("%d", &emp[i].id);
printf("Enter %d Employee dependent names-\n", i+1);
int j;
for(j=0;j<=3;j++)
{
gets(emp[i].dependents);
}
}
int opt;
printf("What do you want to do? Choose a no. from 1 to 5-\n");
scanf("%d", &opt);
if (opt==1)
{
int a=0;
printEmployees (emp[NUM_EMP], a);
}
else
{
printf ("***"); //fill in other functions here
}
}
void printEmployees (employee emp[NUM_EMP], int c)
{
c=0;
for(c=0;c<NUM_EMP;c++)
{
printf("Employee First Name- %s", emp[c].fname);
printf("\nEmployee Last Name- %s", emp[c].lname);
printf("\nEmployee id- %d", emp[c].id);
int j;
for(j=0; j<=3; j++)
{
printf("\nDependent- %s", emp[c].dependents[j]);
}
}
}