알고리즘 컴파일...

바이러스의 이미지

링크드 리스트 알고리즘 짜보았는데...

/*link.h*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _slist List;
typedef struct _slist{
        int num;
        List *next;
        List *prev;
}List;

/*link.c*/
#include "link.h"
void ShowList(List *plist)
{
        List *p;
        p=plist;

        while(p)
        {
        printf("%d\n",p->num);
        p=p->next;
        }
}
void main()
{
        List *pList,*pNew,*pIns;
        pList=(List *)malloc(sizeof(List));
        pList->next=0;
        pList->prev=0;
        pList->num=1;
        printf("root생성시\n");
        ShowList(pList);
        pNew=(List *)malloc(sizeof(List));
        pList->next=pNew;
        pNew->prev=pList;
        pNew->next=0;
        pNew->num=2;

        printf("pNew생성시\n");
        ShowList(pList);

        pIns=(List *)malloc(sizeof(List));
        pIns->num=3;
        pIns->prev=pList;
        pIns->next=pNew;
        pList->next=pIns;
        pNew->prev=pIns;
        printf("pIns생성시\n");
        ShowList(pList);

        pList->next=pNew;
        pNew->prev=pList;
        free(pIns);
        printf("pIns 삭제시\n");
        ShowList(pList);
        free(pNew);
        free(pList);
}

컴파일 에러가 났습니다

에러내역은

link.h:9: redefinition of `List'
link.h:4: `List' previously declared here
link.c: In function `main':
link.c:14: warning: return type of `main' is not `int'
이렇습니다 에러를 잡지 못하겠습니다
많은분들 도움 바람니다 그리고
link.h에서

/*link.h*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _slist{
        int num;
        slist *next;
        slist *prev;
}List;

이렇게 바꾸었더니 에러가...
In file included from link.c:1:
link.h:6: parse error before "_slist"
link.h:6: warning: no semicolon at end of struct or union
link.h:7: warning: data definition has no type or storage class
link.h:8: parse error before '}' token
link.h:8: warning: data definition has no type or storage class
link.c:2: parse error before '*' token
link.c: In function `ShowList':
link.c:4: `p' undeclared (first use in this function)
link.c:4: (Each undeclared identifier is reported only once
link.c:4: for each function it appears in.)
link.c:5: `plist' undeclared (first use in this function)
link.c: In function `main':
link.c:15: `pList' undeclared (first use in this function)
link.c:15: `pNew' undeclared (first use in this function)
link.c:15: `pIns' undeclared (first use in this function)
link.c:16: parse error before ')' token
link.c:22: parse error before ')' token
link.c:31: parse error before ')' token
link.c:14: warning: return type of `main' is not `int'

차이점이 먼지 알고싶습니다

글을 읽어주셔서 감사합니다

envia의 이미지

List를 두 번 정의해서 쓰는 것이 문제가 되는 거니까 아래와 같이 다른 이름으로 해 주면 됩니다.

typedef struct _slist ListNode; 
typedef struct _slist{ 
        int num; 
        ListNode *next; 
        ListNode *prev; 
}List;

:!: 제대로 된 C교재를 한 권 정도 마련하셔서 참고하시는 것도 괜찮은 방법이라고 생각합니다.

----

It is essential, if man is not to be compelled to have recourse, as a last resort, to rebellion against tyranny and oppression, that human rights should be protected by the rule of law.
[Universal Declaration of Human Rights]

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.