링크리스트 삽입부분이 제대로 안되고 안되네요~~헤드가 널값이 아닌경우에요..
이거이름임
질문 제목 : 삽입부분이 제대로 되고 있지 않고 있습니다.질문 요약 :널값이 아니 경우에, 삽입이 제대로 안되고 있어 출력이 안되네요~~
헤드가 널값이 아닌 경우에 제대로 들어가고 않고 있습니다.
질문 내용 :
#include stdio.h
#include stdlib.h
#include malloc.h
#include string.h
struct phone{
char name[10];
char number[20];
struct phone *p; // 다음을 가리키는 포인터
};
void Insertnext(char *name, char *number);
void print(struct phone* cur);
struct phone *head = NULL;
int main(void){
int select = 0;
char name[10] = {0}, number[20] = {0};
while(select!=5)
{
printf(********************** MENU **********************\n);
printf(* 1. New data *\n);
printf(* 4. Print *\n);
printf(* 5. Exit *\n);
printf(**************************************************\n);
printf(Choose the item:);
scanf(%d, &select);
switch(select)
{
case 1:
printf(1. Insert\n);
printf(input name : \n);
scanf(%s, name);
printf(input number : \n);
scanf(%s, number);
// stdin(fflush);
Insertnext(name, number);
break;
case 2:
printf(2. Delete\n);
break;
case 3:
printf(3. Search\n);
break;
case 4:
printf(4. Print All\n);
print(head);
break;
case 5:
printf(5. Exit\n);
break;
}
}
}
void Insertnext(char *name, char *number)
{
//head 포인터가 NULL일 경우
if(head == NULL)
{
head = (struct phone *)malloc(sizeloc(sizeof(struct phone));
strcpy(head-name,name);
strcpy(head-number,number);
head-p = NULL;
}
else //head 가 NULL이 아닐 경우
{
struct phone *cur = NULL; // 임시변수
cur = (struct phone *)malloc(sizeof(struct phone));
cur = head ;
cur - p = head - p;
while(cur - p != NULL){
cur = cur - p ; }
cur - p = NULL;
strcpy(cur - name, name);
strcpy(cur - number, number);
}
}
void print(struct phone* head)
{
struct phone* cur = head;
while(cur!=NULL)
{
printf(%s %s \n, cur-name, cur-number);
cur = cur-p;
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
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 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |
2699816 | 오류 질문입니다.. (1) | 해비치 | 2025-06-29 |
2699763 | 질문입니다 ! 꼭 좀 도와주세요ㅠㅠ (2) | 미라 | 2025-06-28 |
2699555 | c언어 다항식을 입력을 했는데 왜 출력이 안될까요? | 피스케스 | 2025-06-27 |
2699528 | C언어 포인터연산 질문입니다. (3) | 안녕나야 | 2025-06-26 |