연결리스트 탐색 부분 질문입니다 소스있습니당!!
사에
질문 제목 : 분명 똑같다고 나오는데 왜 결과값이 안나올까요??질문 요약 :이 부분이 이상합니다. 제가 하도 이상해서 프린트문으로 다 찍어봤습니다
빨간색 이프문을 만족하지만 프린트문이 실행이 안됩니다. 왜그럴까요 ㅠㅠ
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 입니다
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700668 | c언어 질문입니다. 도와주세요~ (3) | 가자 | 2025-07-07 |
2700639 | 한글입력받아서 ㄱㄴㄷ순서대로출력하는법좀 | 두빛나래 | 2025-07-06 |
2700610 | 정말 기초적인 더하기,여백 문제 help | 무슬 | 2025-07-06 |
2700562 | 함수포인터에서요 (7) | 소심한여자 | 2025-07-06 |
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |