알고리즘 컴파일...
링크드 리스트 알고리즘 짜보았는데...
/*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'
차이점이 먼지 알고싶습니다
글을 읽어주셔서 감사합니다
List를 두 번 정의해서 쓰는 것이 문제가 되는 거니까 아래와 같이 다
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]
댓글 달기