Thanks, CommonTater and anduril, for the advice.
I finally got the first chunk of my code working (I won't say how long it took me as it's embarrassing).
Basically, the big mistake I was making was in not allocating any memory for the Employee types pointed to in the *employees array. Below is my working code. I'd be interested to see if anyone had any suggestions for a better way to code the init_database function in employee.c (or any other suggestions).
main.c:
Code:
#include <stdio.h>
#include "employee.h"
int main (int argc, const char * argv[]) {
const int no_employees = 10;
Employee *employees[10];
init_database(employees, no_employees);
}
employee.h:
Code:
#ifndef employee_h
#define employee_h
typedef struct emp_struct
{ char name[100];
int employee_no;
float salary, tax_to_date;
} Employee;
void init_database (Employee *employees[], int no_employees);
#endif
employee.c:
Code:
#include "employee.h"
#include <string.h>
#include <stdlib.h>
void init_database (Employee *employees[], int no_employees)
{
Employee temp[10] =
{ {"Fred", 10, 10000, 3000},
{"Jim", 9, 12000, 3100.5},
{"Fred", 13, 1000000, 30},
{"Mary", 11, 170000, 40000},
{"Judith", 45, 130000, 50000},
{"Nigel", 10, 5000, 1200},
{"Trevor", 10, 20000, 6000},
{"Karen", 10, 120000, 34000},
{"Marianne", 10, 50000, 12000},
{"Mildred", 10, 100000, 30000}
};
for (int i = 0; i < no_employees; i++) {
employees[i] = (Employee *) malloc(sizeof(Employee));
*employees[i] = temp[i];
}
}