링크드리스트로 전화번호부만들기! 오류ㅜㅜ고쳐주세요
민트맛사탕
이거오류좀고쳐주세요ㅜ_ㅜ틀은맞는것같은데 뭐가틀린지도저히봐도모르겟어유..ㅜㅜ질문 요약 :링크드리스트로 구조체해서 전화번호받기!질문 내용 : 함수전달인자가 틀린것같은데
뭐가틀린거죠ㅜ설명좀해주세요!!!
만약그게틀린게아니면뭐가틀린건지ㅜ
----------------------------------------
ㅠㅠㅠㅠ
#include stdio.h
#include stdlib.h
#include conio.h
#include windows.h
#define MAX 5
struct list{
char name[10];
char number[15];
struct list *link;
};
void insertnode(list **phead, list *p, list *new_node);
list *newnode(char* name, char* number, list* link);
void display(list *head);
list *search(list *head, char* name);
void remove_node(list **phead, list* p, list* removed);
void error(char *message);
int main()
{
list* p=NULL;
list* head=NULL;
p=(list *)malloc(sizeof(list));
head=(list *)malloc(sizeof(list));
char search[10];
char del_name[10];
int a;
head-link = p;
for(int i=0; iMAX; i++)
p = p-link;
while(1)
{
printf( * 전화번호관리 * \n);
printf( -----------------\n);
printf( 1. 전화번호 등록\n);
printf( 2. 전화번호 검색\n);
printf( 3. 전화번호 삭제\n);
printf( 4. 전화번호 출력\n);
printf( 5. 종 료\n);
printf(선택번호를 입력하세요.(1-5)\n);
scanf(%d,&a);
system(cls);
switch(a)
{
case 1 :
printf(이 름 );
gets(p-name);
printf(전화번호 );
gets(p-number);
fflush(stdin);
insertnode(&head, NULL, newnode(p-name,p-number, NULL));
system(cls);
printf(입력이 완료 되었습니다.! \n);
break;
case 2 :
printf( 전화번호를 검색하겠습니다.\n);
printf( 이름을 입력하세요 \n);
gets(search);
search(&head, search);
break;
case 3 :
printf(삭제하실 이름을 입력하세요 );
gets(del_name);
remove_node(&head, &p, search(&head,search));
break;
case 4 :
printf( * 전화번호 전체 리스트 * \n);
printf( ---------------------------------------------\n);
display(head);
break;
case 5:
printf(프로그램 종료를 선택하셨습니다 . \n 아무키나 누르시면 종료됩니다. 감사합니다. ^^);
return 0;
}
}
}
void insertnode(list **phead, list *p, list *new_node)
{
if(*phead ==NULL){
new_node-link=NULL;
*phead = new_node;
}
else if(p==NULL){
new_node-link=*phead;
*phead=new_node;
}
else{
new_node-link=p-link;
p-link=new_node;
}
}
list *newnode(char* name, char* number, list* link)
{
list *new_node;
new_node=(list *)malloc(sizeof(list));
if(new_node==NULL) error(메모리 할당 에러);
strcpy( new_node-name,name);
strcpy(new_node-number,number);
new_node-link=link;
}
void display(list *head){
list *p=head;
while(p != NULL){
printf(이 름 : %15s 번 호 : %15s \n,p-name, p-number);
p=p-link;
}
puts();
}
list *search(list *head, char *name)
{
list *p;
p=head;
while(p!=NULL){
if(p-name==name) return p;
p=p-link;
}
return p;
}
void remove_node(list **phead, list* p, list* removed)
{
if(p==NULL)
*phead = (*phead)-link;
else
p-link=removed-link;
free(removed);
}
void error(char *message)
{
fprintf(stderr, %s\n, message);
exit(1);
}