구조체 안의 구조체의 자료구조 질문입니다

ch0nn0m의 이미지

밑에와 같이 단일연결리스트로...구성했는데요...
channle안에 user의 이름을 각각 따로 저장해서...
그 해당되는 channel을 부르면 그 채널에 저장된 user의 이름만 출력해보고 싶은데요..
저는 어떻게 자꾸...모든 channel 이 하나의 user 리스트를 공유하게 만들어지는듯 합니다.
어떻게 구성해야되나요??

typedef struct _user
{
        char u_name[20];
        struct _user *u_next;
}user;
user *u_head, *u_tail;
 
typedef struct _channel
{
        int user_count;
        char channel_name[20];
        struct _channel *c_next;
        struct _user *user;
}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;
}
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;
}

freestyle의 이미지

구조체 하나를 박스 하나로 잡고, 손으로 직접 연결해 보세요.

생성, 초기화, 연결 등의 과정 하나하나가 함수로 떨어지면 바람직한 결과입니다.
그림으로 못 그린다면 개념을 파악하고 있지 못하다는 것입니다.

말씀을 들어보면 user *u_head, *u_tail;를 잘못 쓰고 계신 것 같네요.

user *userlist_head, *userlist_tail;로 보기 좋게 이름을 지어
채널 구조체 안에 집어 넣으세요.

struct _user *user;는 빼시고요.

채널에 유저를 추가할 때는 a_channel->userlist_head를 따라가서 next가 userlist_tail일 때까지 루프 돌다가
그 사이에 넣어주면 되고요,

유저를 출력할 때는 a_channel->userlist_head를 따라가서 NULL을 만나거나 현재 노드가 userlist_tail이 가리키는 것과 일치할 때까지
하나씩 출력해 주시면 되고요.

그림을 그리세요... 몇 번 확인해가면서 그리다보면 본인이 무엇을 잘못 알고 있었는지 알게 됩니다.
-----------------------
Go to the U-City

----------------------------------------------------------------------------------------
Don't Feed the Trolls!
----------------------------------------------------------------------------------------

kknd8080의 이미지

2차원링크드리스트를 만드세요

배열로 보면 a[10][10];

a[0][0] = 0번 채널의 0번 유저고
a[1][0] = 1번 채널의 0번 유저조

이걸 링크드 리스트로만 구성하시면 될것같습니다.

유저를 모든 채널이 공유한다고 하셧는데 그건 검색이나 입력이 잘못된거 같습니다.

한 채널에 유저를 애드시키고 검색하겟조.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.