연결리스트 탐색 부분 질문입니다 소스있습니당!!
사에
질문 제목 : 분명 똑같다고 나오는데 왜 결과값이 안나올까요??질문 요약 :이 부분이 이상합니다. 제가 하도 이상해서 프린트문으로 다 찍어봤습니다
빨간색 이프문을 만족하지만 프린트문이 실행이 안됩니다. 왜그럴까요 ㅠㅠ
void search(head * l)
{
node * stud;
node * temp;
stud = (node *)malloc(sizeof(node));
temp = (node *)malloc(sizeof(node));
//printf(%s %s %s, l-head, );
temp = l-head;
printf(temp = %s l-head = %s , temp, l-head);
printf(num?); scanf(%s, stud-num);
printf(temp-num = %s stud-num = %s \n, temp-num, stud-num);
//while(temp != null)
//{
if(temp-num == stud-num)
{
printf(%s %s\n, temp-name, temp-num);
}
temp = temp-link;
//}
}
질문 내용 :
#include stdio.h
#include stdlib.h
#include string.h
int sel;
char x[10];
typedef struct node{
char name[20];
char num[10];
struct node * link;//네임과 넘을 지정하고 리스트 노드를 가르키는 link 선언
}node;
//typedef struct node node;
typedef struct{
node * head;//노드를 가르키는 head 선언
}head;
//typedef struct aaaa head;
head * createhead(void);//헤드노드를 만들고 리턴값을 헤드포인터로 받음
void addlastnode(head *, node *);
void printlist(head *);
void insertnode(head * l);
void search(head * l);
void searchnode(head * l, node * serchch);
head * createhead(void)//헤드를 만드는 함수
{
head * l;//노드를 가르키는 head 구조를 가르치는 l 구조체를 만듬
l = (head *)malloc(sizeof(head));
l-head = null;
return l;
}
void insertnode(head * l)//이름과 학번을 입력받는 함수
{
node * student;
student = (node *)malloc(sizeof(node));
printf(name?); scanf(%s, student-name);
printf(num?); scanf(%s, student-num);
addlastnode(l, student);
}
void addlastnode(head * l, node * student)//삽입하는 함수
{
node * newnode;
node * p;
newnode = (node *)malloc(sizeof(node));
strcpy(newnode-name, student-name);
strcpy(newnode-num, student-num);
newnode-link=null;
if( l-head == null )
{
l-head=newnode;
return;
}
p = l-head;
while(p-link!=null)
{
p=p-link;
}
p-link=newnode;
}
void search(head * l)
{
node * stud;
node * temp;
stud = (node *)malloc(sizeof(node));
temp = (node *)malloc(sizeof(node));
//printf(%s %s %s, l-head, );
temp = l-head;
printf(temp = %s l-head = %s , temp, l-head);
printf(num?); scanf(%s, stud-num);
printf(temp-num = %s stud-num = %s \n, temp-num, stud-num);
//while(temp != null)
//{
if(temp-num == stud-num)
{
printf(%s %s\n, temp-name, temp-num);
}
temp = temp-link;
//}
}
/*void searchnode(head * l, node * student)//이름과 학번을 입력받아 찾는 함수
{
node * temp;
temp = l-head;
while(temp != null)
{
if(temp-num == student-num)
{
printf(%s %s\n, temp-name, temp-num);
}
temp = temp-link;
}
printf(%s %s\n, temp-name, temp-num);
}*/
void printlist(head * l)//출력하는 함수
{
node * p;
p = l-head;
while(p != null)
{
printf(%s %s\n, p-name, p-num);
p = p-link;
if(p != null)
{
printf();
}
}
}
int main()
{
head * l;
l = createhead();
printf(**********attendance**********\n);
printf(1. insert \n);
printf(2.&nbnbsp; search \n);
printf(3. delete \n);
printf(4. look \n);
printf(5. exit \n);
while(1)
{
printf(what number?);
scanf(%d, &sel);
switch(sel)
{
case 1:
insertnode(l);
printf(insert success!\n);
break;
case 2:
search(l);
break;
case 3:
break;
case 4:
printlist(l);
break;
case 5:
printf(exit attendance\n);
return 0;
}
}
}
-
상큼한캔디
temp-num은 숫자이므로 %d 입니다
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2695766 | 달팽이 배열 어디서 틀렸는지 모르겠습니다ㅠㅠ | 연분홍 | 2025-05-23 |
2695738 | fopen과fclose질문~~ (5) | 희선 | 2025-05-23 |
2695707 | 3의 배수 나타내기. (2) | 수리 | 2025-05-23 |
2695626 | 피보나치수열 과제 때문에 질문 드립니다. (6) | 옆집언니 | 2025-05-22 |
2695595 | 포인트공부중입니다 int형에서 4=1 인가요? (3) | 족장 | 2025-05-22 |
2695567 | 드라이브 고유번호를 가져오는 함수 (2) | 초코맛사탕 | 2025-05-21 |
2695533 | 음수의 산술변환! 질문이요 ㅠㅠ... (4) | 꽃여름 | 2025-05-21 |
2695506 | 구조체 배열 이용 도서목록 출력 프로그램 (1) | 가을귀 | 2025-05-21 |
2695450 | c언어 함수 질문이요.... | 이슬비 | 2025-05-20 |
2695403 | VirtualAlloc함수 및 메모리 질문 | 크리에이터 | 2025-05-20 |
2695355 | c언어 for함수 | 미쿡 | 2025-05-19 |
2695327 | 안녕하세요 제가 이번에 좀 큰 프로그램을.. | 악당 | 2025-05-19 |
2695295 | mutex동기화의 thread기반 채팅 서버소스 질문입니다 | 그루터기 | 2025-05-19 |
2695270 | 질문이요..swap 관한겁니다..ㅠㅠ (3) | 콩알녀 | 2025-05-19 |
2695244 | 노땅초보궁금한게 하나 있는데요..반복문(while문)초보자질문 (6) | 큰꽃늘 | 2025-05-18 |
2695166 | do while 문 어떤것이잘못된건지 모르겠어요 (2) | 아이폰 | 2025-05-18 |
2695122 | 구조체에 대해 물어보고 싶은게 있습니다 ^^^.. (7) | 수련 | 2025-05-17 |
2695091 | txt 파일 입출력 후 2차 배열에 저장하기입니다. (3) | 헛장사 | 2025-05-17 |
2695063 | 수도요금 프로그램좀 짜주세요. | 시내 | 2025-05-17 |
2695033 | 답변좀요ㅠㅠ (1) | 비사벌 | 2025-05-16 |