단일연결리스트 질문이요 !!
바로찬글
질문 제목 : 입력부분에 문제가 있는것 같은데
잘 모르겠어서 여기에 질문해 봅니다..ㅠㅠ / insert() 요 부분이요!단일연결리스트를 동적할당을 통해서 입력시켜볼려구하는데 어렵네요 ㅠ질문 내용 :
#include stdio.h
#include string.h
#include stdlib.h
typedef struct book{
char name[10];
char number[20];
char adr[50];
struct book *link;
}book;
struct book *head = null;
struct book *tail = null;
struct book *temp = null;
void insert();
void print();
void search();
void del();
void main()
{
int n=0;
while(1)
{
printf( ★★★주소록 프로그램 ★★★\n);
printf( ★★원하시는 기능을 선택 해주세요★★\n);
printf( 1.입력 \n);
printf( 2.출력 \n);
printf( 3.검색 \n);
printf( 4.삭제 \n);
printf( 5.종료 \n);
printf( );
scanf_s(%d,&n);
switch(n)
{
case 1:
system(cls);
insert();
break;
case 2:
system(cls);
print();
break;
case 3:
system(cls);
search();
break;
case 4:
system(cls);
del();
break;
case 5:
printf(프로그램을 종료합니다. \n);
exit(1);
default:
printf(1~5 숫자만 입력하세요.\n);
}
}
}
void insert()
{
book *item;
item = head;
temp=(book *)malloc(sizeof(book));
printf(이름:);
scanf_s(%s, head-name);
printf(\n);
printf(번호:\n);
scanf_s(%s, head-number);
printf(\n);
printf(주소:\n);
scanf_s(%s, head-adr);
printf(\n);
temp-link = null;
if(head==null){
head = temp;
}
else{
while(item != null)
{
item-link = temp;
}
}
}
void print()
{
book *item;
item = head;
printf(저장된 주소록\n);
if(item == null){
printf(출력할 값이 없습니다.\n);
return;
}
while(item != null)
{
printf(이름: %s, item-name);
printf(주소: %s, item-adr);
printf(전화번호: %s, item-number);
item = item-link;
}
}
void search()
{
char search[10];
book *item;
item = head;
if(item == null){
printf(검색할 값이 없습니다.\n);
return;
}
printf(검색할 주소록의 이름 입력: );
scanf_s(%s, search);
while(item != null)
{
if(strcmp(item-name,search) == 0){
printf(이름: %s, item-name);
printf(주소: %s, item-adr);
printf(전화번호: %s, item-number);br /r);
return;
}
}
printf(일치하는 주소록이 없습니다.);
}
void del()
{
char search[10];
book *item;
item = head;
temp=(book *)malloc(sizeof(book));
if(item == null){
printf(삭제할 값이 없습니다.\n);
return;
}
printf(주소록에서 삭제할 이름: );
scanf(%s, search);
if(strcmp(head-name, search) == 0){
head = head-link;
printf(삭제 완료);
return;
}
while(item != null)
{
if(strcmp(item-name, search) == 0){
temp = (item-link)-link;
free(item-link);
item-link = temp;
printf(삭제완료);
return;
}
}
printf(일치하는 이름이 없습니다.);
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
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 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |