유니언 질문입니다.ㅜㅜ
볼수록매력
완전 초보라서 잘몰라서요 고수님들 도와주세요....ㅜㅜ대충 짜봤는데 실행이 안돼네요....뭐가 문제가 있는 걸까요???/;;;;질문 내용 :
#include stdio.h
#include string.h
#define false 0
#define true 1
typedef struct {
enum tagfield{female, male}sex;
union {
int chidren;
int beard;
} u;
}sex_type;
typedef struct
{
char name[10];
int age;
float salary;
sex_type sex_info;
}human_being;
human_being person1,person2;
int main()
{
human_being person 1, person 2;
strcrp(person 1.name, ha-ja);
person1.age = 23;
person1.salary = 2500;
strcpy(person 2.name, young-guen);
person2.age = 23;
person2.salary = 2400;
person1.sex_info.sex = male;
person1.sex_info.u.beard_ = false;
person2.sex_info.sex = female;
person.sex_info.u.children = 4;
int humansequal (humanbeing person1, humanbeing person 2)
/* 만일 personal과 person2가 동일인이면 true를 반환하고 그렇지
않으면 false를 반환한다. */
if (strcpy(person1.name, person2.name))
return false;
if (person1.age != person2.age)
return false;
if (person1.salary != person2.salary)
return false;
return true;
}
-
봄여울
ㄴ 정말 감사합니다....^^
-
알
틀린 부분이 좀 많네요.
strcpy(person2.name,\young-guen\);
- name[10] 인데, null문자를 빼고 10개의 문자를 넣고 있군요. name을 좀 더 넉넉하게 잡아주세요.
person1.sex_info.u.beard_=FALSE;
- beard_ 라는 변수는 union에 없습니다.
그리고, main 안에서 humansEqual이라는 함수를 정의하고 계시네요.
main 밖으로 빼셔서 정의하시고, 함수 프로토타입도