doubly list 정렬하는 건데 왜 오류뜨는지모르겠어요 ㅠㅠ 고수님들 좀봐주세요
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct list_node * PTR;
typedef struct list_node {
char data[3];
PTR rlink;
PTR llink;
}list_node;
void printList(PTR * head);
void insert(PTR *ptr, char *item);
void insert(PTR *ptr, char *item)
{
PTR newnode, temp;
newnode = (PTR)malloc(sizeof(PTR));
strcpy(newnode->data, item);
if ((*ptr)->rlink == *ptr) //빈노드일때 노드 추가
{
newnode->rlink = *ptr;
newnode->llink = *ptr;
(*ptr)->rlink = newnode;
(*ptr)->llink = newnode;
temp = newnode;
}
else
{
temp = (*ptr)->rlink;
while (1)
{
if (strcmp(temp->data, item) > 0)
{
newnode->rlink = temp;
newnode->llink = temp->llink;
temp->llink = newnode;
temp->llink->rlink = newnode;
break;
}
else if (((*ptr)->llink->data,item) < 0)
{
newnode->rlink = temp->rlink;
newnode->llink = temp;
temp->rlink = newnode;
temp->rlink->llink = newnode;
break;
}
else
temp = temp->rlink;
}
}
}
void printList(PTR * head) {
PTR temp;
printf("\n<print list>\n");
/* list의 처음부터 끝까지 이동하면서 data값 출력 */
temp = *head;
do
{
temp = temp->rlink;
printf("%s\t", temp->data);
} while (temp->rlink != (*head));
printf("\n");
}
int main(void)
{
FILE *fp;
char input[3];
PTR head;
head = (PTR)malloc(sizeof(PTR)); //더미노드생성
head->rlink = head;
head->llink = head;
strcpy(head->data, NULL);
fp = fopen("Data5.txt", "r");
if (!fp){ printf("Can't read the file\n"); exit(0); }
while (!feof(fp)) {
fscanf(fp, "%s", input); /* 파일에서 하나씩 읽어오면서 리스트에 추가 */
insert(&head, input);
printf("\ninput: %s", input);
printList(&head);
}
printf("\nresult: ");
printList(&head);
fclose(fp);
}
여러군데여 박는데 와 하나만 할당해놓냐
글쓴인데 무슨말이에요??
어디서 에러나는데여
디버깅성공해서 콘솔창뜨면 아무것도안나오고 오류뜸 이거 오버플로우라던데 어떻게고쳐야될지모르겠어요
대딩때 자료구조로 며칠 밤 새 봐야 내공이 쌓이지...ㅎㅎ
코드가 너무지저분해서...
일단 char input을 100정도로 늘이세요
ㅜㅜ 여기서 더 진전이없어요 오류도 안잡아주니까 어디를어떻게고쳐야될지도모르겠음..
코드 지저분해서 뵈기 싫다... 담에 할떄는 구조체로 하지말고 클래스로 해봐라 일단