I'm trying to write a function in C that takes a struct array (of structs that hold employee information) as an argument and prints each member of each struct. For some reason my code isn't producing any output. Could anyone tell me where I am going wrong? Thanks.
Here it is:
#include <stdio.h>
#include <stdlib.h>
typedef struct Employee
{
int number;
char name[20];
char department[15];
double salary;
}Employee;
void employeePrint(Employee arr[]);
main()
{
Employee e1 = {101,"John Smith\0","Accounting\0",54926.25};
Employee e2 = {102,"Jane Q. Public\0","Retail\0",54926.24};
Employee e3 = {103,"George Washington\0","Tech\0",70417.76};
Employee empArr[3] = {e1,e2,e3};
employeePrint(empArr);
}
void employeePrint(Employee arr[])
{
int i;
for(i = 0; i < sizeof(arr)/sizeof(arr[0]); ++i)
{
printf("Number: %-4d\n",arr[i].number);
printf("Name: %-6s\n",arr[i].name);
printf("Department: %s\n",arr[i].department);
printf("Salary: $%-2.2lf",arr[i].salary);
printf("----------------");
}
}