링크리스트 삽입부분이 제대로 안되고 안되네요~~헤드가 널값이 아닌경우에요..
이거이름임
질문 제목 : 삽입부분이 제대로 되고 있지 않고 있습니다.질문 요약 :널값이 아니 경우에, 삽입이 제대로 안되고 있어 출력이 안되네요~~
헤드가 널값이 아닌 경우에 제대로 들어가고 않고 있습니다.
질문 내용 :
#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;
}
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2693984 | 오버로딩이 무엇인가요? (2) | 헛매질 | 2025-05-07 |
2693956 | PlaySound재생이 안됩니다!(C에 음악넣기) | 지존 | 2025-05-06 |
2693928 | &와 *의 사용에 관한 명확한 이해 | 제나 | 2025-05-06 |
2693903 | 반복문 설명좀요 ㅠㅠ (2) | 란새 | 2025-05-06 |
2693869 | stdio.h 는 왜 쓰는건가요? (1) | 큰꽃들 | 2025-05-06 |
2693842 | 포인터 변수의 주소값끼리 더하는 것에 대해서 질문드립니다. (1) | 진솔 | 2025-05-05 |
2693811 | 소수 출력;;;; | 화이트캣 | 2025-05-05 |
2693788 | 이런 함수는 없나요? (3) | 앤드류 | 2025-05-05 |
2693758 | txt파일 불러와서 행렬로 저장 | 큰애 | 2025-05-05 |
2693727 | scanf 오류 문제!! (2) | 큰나래 | 2025-05-04 |
2693704 | 구조체 주소록 문제인데 도와주세요 (2) | 도1도캣 | 2025-05-04 |
2693676 | 열혈강의 c언어 질문입니다 | 하양이 | 2025-05-04 |
2693647 | 12.620000 을요 12.620 으로 어떻게 표현해요? (2) | 파도 | 2025-05-04 |
2693619 | 타이틀 코드.. | 단순드립 | 2025-05-03 |
2693591 | 컴파일 에러에서 질문드립니다 (3) | 게자리 | 2025-05-03 |
2693463 | 동적할당 이용시 fwrite사용을 어떻게 해야하나요..? (10) | 일본어못해요 | 2025-05-02 |
2693387 | 배열문제입니다 수정오류캡쳐했습니다 (6) | 연하얀 | 2025-05-01 |
2693356 | text 입출력 내림차순 질문입니다 ㅠ | 빛글 | 2025-05-01 |
2693328 | C언어를이용해서 .txt파일 외에 다른 확장자 파일 삭제가 가능한지.. (2) | 대나무 | 2025-05-01 |
2693299 | 파일입출력 바이너리파일 | 독특한 | 2025-04-30 |