I made your code a tad bit better from my prespective. The CmpEmployee function needed to trim down on those else's. Also the myStrCmp could be easily replaced with strcmp.
Code:
cmp = eFalse;
return (cmp);
Could be easily trimmed down to:
I also thought the
Code:
typedef enum{
eFalse = 0,
eTrue = 1
} myBoolean;
Was an overkill if you just want TRUE & FALSE you could add these to the top of your file:
Code:
#define TRUE 1
#define FALSE 0
And
Code:
y= CmpEmployee(struct personal employee[2],struct personal employee[0]);
should be replaced with:
Code:
y= CmpEmployee(employee[2], employee[0]);
Though of course you'd have to create the arrays that create employee[0] and employee[2]. Here's another version for you to use as a creative reference:
Code:
#include <stdlib.h>
#include <stdio.h>
#define FALSE 0
#define TRUE 1
#define MALE 1;
#define FEMALE 2;
/// STRUCTURES
struct Sbirth {
double Birth_year;
double Birth_month;
double Birth_day;
};
struct Sstuff {
char street[50];
char city[50];
char state[15];
char zip[10];
};
struct personal {
char F_name[50];
char L_name[50];
double salary;
int gender;
int ID_Number;
struct Sbirth birth;
struct Sstuff stuff;
};
int CmpEmployee(struct personal emp1,struct personal emp2);
/// MAIN
int main() {
int cmp;
struct personal Employee1;
Employee1.ID_Number = 1;
strcpy(Employee1.F_name, "Kleid");
strcpy(Employee1.L_name, "Wilson");
Employee1.salary = 200;
Employee1.gender = MALE;
Employee1.birth.Birth_year = 1987;
Employee1.birth.Birth_month = 7;
Employee1.birth.Birth_day = 8;
strcpy(Employee1.stuff.zip, "3434");
strcpy(Employee1.stuff.state, "OR");
strcpy(Employee1.stuff.city, "Portland");
strcpy(Employee1.stuff.street, "Miracle Street");
struct personal Employee2;
Employee2.ID_Number = 2;
strcpy(Employee2.F_name, "Jesus");
strcpy(Employee2.L_name, "Christ");
Employee2.salary = 2;
Employee2.gender = MALE;
Employee2.birth.Birth_year = 1;
Employee2.birth.Birth_month = 12;
Employee2.birth.Birth_day = 25;
strcpy(Employee2.stuff.zip, "37322");
strcpy(Employee2.stuff.state, "ISLAM");
strcpy(Employee2.stuff.city, "Jerusalem");
strcpy(Employee2.stuff.street, "Jerusalem dr.");
struct personal Employee3;
Employee3.ID_Number = 1;
strcpy(Employee3.F_name, "Kleid");
strcpy(Employee3.L_name, "Wilson");
Employee3.salary = 200;
Employee3.gender = MALE;
Employee3.birth.Birth_year = 1987;
Employee3.birth.Birth_month = 7;
Employee3.birth.Birth_day = 8;
strcpy(Employee3.stuff.zip, "3434");
strcpy(Employee3.stuff.state, "OR");
strcpy(Employee3.stuff.city, "Portland");
strcpy(Employee3.stuff.street, "Miracle Street");
if(CmpEmployee(Employee1, Employee2))
printf("%s & %s are the same!\n", Employee1.F_name, Employee2.F_name);
else
printf("%s & %s are different!\n", Employee1.F_name, Employee2.F_name);
if(CmpEmployee(Employee1, Employee3))
printf("%s & %s are the same!\n", Employee1.F_name, Employee3.F_name);
else
printf("%s & %s are different!\n", Employee1.F_name, Employee3.F_name);
return 0;
}
// Return true if they are identical employees
int CmpEmployee(struct personal emp1,struct personal emp2) {
double const nEmployee1[] = {
emp1.ID_Number,
emp1.gender,
emp1.birth.Birth_month,
emp1.birth.Birth_day,
emp1.birth.Birth_year
};
char const *szEmployee1[] = {
emp1.F_name,
emp1.L_name,
emp1.stuff.street,
emp1.stuff.city,
emp1.stuff.state,
emp1.stuff.zip
};
double const nEmployee2[] = {
emp2.ID_Number,
emp2.gender,
emp2.birth.Birth_month,
emp2.birth.Birth_day,
emp2.birth.Birth_year
};
char const *szEmployee2[] = {
emp2.F_name,
emp2.L_name,
emp2.stuff.street,
emp2.stuff.city,
emp2.stuff.state,
emp2.stuff.zip
};
int i;
// Compare numerical data:
for(i=0; i<5; i++) {
if(nEmployee1[i] != nEmployee2[i])
return FALSE;
}
// Compare string data:
for(i=0; i<6; i++) {
if(strcmp(szEmployee1[i], szEmployee2[i])) // If the strings are the same
return FALSE; // Then the employees aren't the same!
}
return TRUE;
}
I hope this helps you :)