링크드 리스트 에러 ㅜ
달빛
질문 제목 : 링크드 리스트 에러질문 요약 :메뉴 1번 학생 입력부분에서 입력수 1, 2개는 잘입력되고 잘출력되는데..
3명이상입력할때.. 3번째 학생입력에서 에러가 납니다..
코딩 에러면 그나마 좋을텐데..
작동시 에러라... 헤메고있어요.. 도와주세요~질문 내용 :
#includestdio.h
#includestdlib.h
#includestring.h
typedef struct student{
int number;
char name[20];
char phone[20];
char address[100];
struct student *next;
}student;
void start(void);
void body(void);
student *append(student *node, student *temp);
void print(student *node);
int main()
{
start();
}
void start(){
int i;
printf(1.학생입력, 2.학생검색, 3.리스트 출력 :);
scanf(%d, &i);
if(i == 1)
{
body();
}
else if(i==2)
{
search();
}
}
void body(){
int input, i;
student *node=null, *temp=null;
printf(몇명을 입력하시겠어요?);
scanf(%d, &input);
fflush(stdin);
for(i=0; iinput; i++)
{
temp = (student *)malloc(sizeof(student));
temp-number = i+1;
printf(%d번 학생, temp-number);
printf(이름을 입력하세요:);
gets(temp-name);
//fgets(temp-name,20,stdin);
///*fgets를 사용하면 배열사이즈를 넘지않을 경우 엔터도 입력되어 한칸띄어져서 출력된다.
fflush(stdin);
printf(폰 번호를 입력하세요:);
gets(temp-phone);
fflush(stdin);
printf(주소를 입력하세요:);
gets(temp-address);
fflush(stdin);
temp-next = null;
node = append(node, temp);
}
print(node);
}
student *append(student *node, student *temp)
{
student *link = node;
if(node == null){
node = temp;
}
else{
while(link-next != null)
{
link-next;
}
link-next = temp;
}
return node;
}
void print(student *node)
{
student *temp = node;
do{
printf(%d번\t, temp-number);
printf(이름:%s\t, temp-name);
printf(전화번호:%s\t, temp-phone);
printf(주소:%s\n, temp-address);
temp = temp-next;
}while(temp != null);
}
-
연분홍
혼자서 해결 ㅜㅜ... 역시 놀다오니까.. 머리가 새롭네.