Hello,
So I am just messing around using separate files to keep the main.c file not so cluttered up. It work's but I thought that it wouldn't. Maybe I am misunderstanding how it works, but for some reason, I did not #include the "Employee_def.c" file, yet the main.c file still knows what that function is, I thought I'd have to #include the Employee_def.c file.
Also, I am getting a warning in the main.c file on the line I call the Employee_Initializer function that states "Implicit declaration of function "Employee_Initializer" is invalid in C99". Still works, but not sure what that warning is trying to say.
ANY help with an explanation or protips would be greatly appreciated!
main.c
#include <stdio.h>
#include "Employee.h"
////////////////////////////////////////////////////////////////////
//
//
// MAIN
//
//
////////////////////////////////////////////////////////////////////
int main(int argc, const char * argv[])
{
Employee emp;
Employee * emp_ptr = &emp;
Employee_Initializer(emp_ptr);
return 0;
}
Employee.h
typedef struct {
int age;
int id;
char sex;
float pay_rate;
float vac_hours;
float sick_hours;
float personal_hours;
char first_name[20];
char last_name[20];
char job_title[25];
char address[55];
} Employee;
Employee_def.c
#include <stdio.h>
#include "Employee.h"
// Employee Inializer
void Employee_Initializer(Employee * emp) {
emp->pay_rate = 10.25;
emp->vac_hours = 0;
emp->sick_hours = 0;
emp->personal_hours = 0;
emp->age = 0;
do {
printf("Enter New Employee's Age: ");
scanf("%d", &emp->age);
} while(emp->age < 18);
printf("Age: %d\n", emp->age);
}