구조체안의 구조체
훌림목
질문 제목 : 구조체안의 구조체구조체안의 구조체를 선언한후 안에 들어있는 구조체에 메모리를 할당하는방법질문 내용 :
channel이라는 구조체에 user라는 구조체를 하나더 만들어
각 channel마다 user를 받아서 출력하는 것을 해보려는데요
연결리스트를 사용하는 초기설정에서...
typedef struct _user
{
char u_name[20];
struct _user *u_next;
}user;
typedef struct _channel
{
int user_count;
char channel_name[20];
struct _channel *c_next;
user *u_head, *u_tail;}channel;
channel *c_head, *c_tail;
void init_user(void)
{
u_head=(user*)malloc(sizeof(user));
u_tail=(user*)malloc(sizeof(user));
u_head-u_next=u_tail;
u_tail-u_next=u_tail;
}//이부분에서 channel안의 u_head에 메모리를 할당하고 싶은데 이렇게가 아닌거 같아서요
void init_channel(void)
{
c_head=(channel*)malloc(sizeof(channel));
c_tail=(channel*)malloc(sizeof(channel));
c_head-c_next=c_tail;
c_tail-c_next=c_tail;
}
-
첫삥
저 상태에서는 channel 의 객체가 없기 때문에...;