-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.c
More file actions
232 lines (226 loc) · 9.23 KB
/
Copy pathfunction.c
File metadata and controls
232 lines (226 loc) · 9.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include "header.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void SelectMenu(){ //메뉴 보여주기 함수
printf("\n----------옵션을 선택하세요----------\n");
printf("0. 서울 시내 도서관 검색하기\n1. 서울시 전체 도서관 보기\n2. 새로운 도서관 추가하기\n3. 사라진 도서관 삭제하기\n4. 실수로 삭제한 도서관 되살리기\n5. 도서관 정보 수정하기\n6. 오늘의 도서관 추천받기\n7. 도서관 정보 저장하기\n8. 종료하기\n\n옵션의 번호를 입력해주세요!>>");
}
void Print(library *list[], int count){// print 함수
printf("****************************\n");
printf("도서관 일련번호 도서관명 구 코드 구명 주소 정기 휴관일 전화번호\n");
for(int i=0;i<count;i++){//하나씩 프린트
if(list[i]->index==-1) continue;
printf("%2d",i+1);// 삭제된 데이터는 표시하지 않음.
printf(" %d %s %d %s %s %s %s\n",list[i]->number,list[i]->name,list[i]->localnum,list[i]->localName,list[i]->address,list[i]->hollyday,list[i]->callnum);
}
}
void Create(library *list[], int count) { // 새로운 list 추가 함수
printf("도서관 일련번호?");
scanf("%d",&list[count]->number);
printf("도서관명? ");
getchar();
fgets(list[count]->name,300,stdin);
list[count]->name[(strlen(list[count]->name)-1)]='\0';
printf("구 코드? ");
scanf("%d",&list[count]->localnum);
printf("구명? ");
getchar();
fgets(list[count]->localName,20,stdin);
list[count]->localName[(strlen(list[count]->localName)-1)]='\0';
printf("주소? ");
fgets(list[count]->address,1000,stdin);
list[count]->address[(strlen(list[count]->address)-1)]='\0';
printf("정기 휴관일? ");
fgets(list[count]->hollyday,1000,stdin);
list[count]->hollyday[(strlen(list[count]->hollyday)-1)]='\0';
printf("전화번호? ");
fgets(list[count]->callnum,1000,stdin);
list[count]->callnum[(strlen(list[count]->callnum)-1)]='\0';
printf("생성 완료되었습니다!\n");// 생성 완료 메시지 출력
}
void Modify(library *list[], int count){
int number;//받을 일련번호
int listnum;// 받은 일련번호와 일치하는 도서관 일련번호의 index
printf("수정할 도서관의 일련번호를 입력하세요");
scanf("%d",&number); // 일련 번호 입력 받기
for(int i=0;i<count;i++){//입련 받은 일련 번호와 일치하는 것 찾기
if(list[i]->index==-1) continue;
if(number==list[i]->number){
listnum=i;
break;
}
}
printf("%s 수정\n",list[listnum]->name);
// 일치하는 도서관 수정
printf("도서관 일련번호? ");
scanf("%d",&list[listnum]->number);
printf("도서관명? ");
getchar();
fgets(list[listnum]->name,300,stdin);
list[listnum]->name[(strlen(list[listnum]->name)-1)]='\0';
printf("구 코드? ");
scanf("%d",&list[listnum]->localnum);
printf("구명? ");
getchar();
fgets(list[listnum]->localName,20,stdin);
list[listnum]->localName[(strlen(list[listnum]->localName)-1)]='\0';
printf("주소? ");
fgets(list[listnum]->address,1000,stdin);
list[listnum]->address[(strlen(list[listnum]->address)-1)]='\0';
printf("정기 휴관일? ");
fgets(list[listnum]->hollyday,1000,stdin);
list[listnum]->hollyday[(strlen(list[listnum]->hollyday)-1)]='\0';
printf("전화번호?");
fgets(list[count]->callnum,1000,stdin);
list[count]->callnum[(strlen(list[count]->callnum)-1)]='\0';
printf("수정 완료");
}
void Delete(library *list[], int count){
printf("==> 폐업하였거나, 영업중이지 않은 도서관의 '일련번호'를 입력해주세요 >> ");
int check=0;
int deletenum; //삭제할 일련번호 받는 변수
scanf("%d", &deletenum); //받기
for(int i = 0; i<count; i++){
if(list[i]->number==deletenum){ //list[i]->일련번호가 deletenum이면 list[i]->index = -1로 만들기
list[i]->index = -1;
check++;
printf("%s의 정보가 삭제되었습니다!\n", list[i]->name);
break;
}
else continue;
}
if(check==0)
printf("해당 정보는 존재하지 않습니다.\n");
}
void Recover(library *list[], int count){// 복구 함수
int number; // 복구할 도서관의 일련번호 받기
printf("삭제된 도서관:\n"); // 삭제된 도서관들 출력
printf("****************************\n");
printf("도서관 일련번호 도서관명 구 코드 구명 주소 정기 휴관일 전화번호\n");
for(int i=0;i<count;i++){
if(list[i]->index==-1){
printf("%2d",i+1);
printf(" %d %s %d %s %s %s %s\n",list[i]->number,list[i]->name,list[i]->localnum,list[i]->localName,list[i]->address,list[i]->hollyday,list[i]->callnum);
}
}
printf("복구할 도서관의 일련번호 입력 : ");
scanf("%d",&number);
for(int i=0;i<count;i++){
if(number==list[i]->number){// 일련번호 일치하는 도서관 복구
if(list[i]->index==-1){
list[i]->index=i;
printf("%s의 정보가 복구되었습니다!\n", list[i]->name);
break;
}
printf("%s는 삭제된 도서관이 아닙니다.\n", list[i]->name);
break;
}
}
}
void Search(library *list[], int count){// 검색 함수
getchar();
char name[100];// 검색할 도서관 이름
int num;// 검색 榮쩝 확인
printf("검색할 도서관 이름 입력 : ");
fgets(name,20,stdin);
name[(strlen(name)-1)]='\0';
printf("****************************\n");
printf("도서관 일련번호 도서관명 구 코드 구명 주소 정기 휴관일 전화번호\n");
for(int i=0;i<count;i++){// 같거나, 검색된 이름이 포함된 도서관이 있으면 출력
if(strstr(list[i]->name,name)!=NULL){
printf("%2d",i+1);
printf(" %d %s %d %s %s %s %s\n",list[i]->number,list[i]->name,list[i]->localnum,list[i]->localName,list[i]->address,list[i]->hollyday,list[i]->callnum);
}
}
if(num==0)
printf("검색하신 도서관을 찾을 수 없습니다. 이름을 다시한번 확인해주세요!\n");
}
int LoadData(library *list[]){
FILE* fp = fopen("Library_Info.csv", "rt"); //파일 열기
char dummy[400]; //첫줄 없애기용 더미
fgets(dummy, 400, fp); //첫줄 없애기
int count = 0; //파일에 몇개 데이터 있는지 리턴해야함
if(fp==NULL){ //파일이 없을 때
printf("==>파일이 없습니다!\n");
return 0;
}
else{ //정상적으로 들어왔을 때
while(1){
if(feof(fp)){
printf("==>파일을 불러왔습니다!\n");
break;
}
else{
char val[400]; //fgets한거 담기는 변수
int tokcount = 0; //토큰 분리할 때, 0번째는 atoi로 바꾸고, 1번째는 strcpy해야하고... 여러 변수가 있으니까 씀
fgets(val, 400, fp);
char *p = strtok(val, ","); //strtok로 "," 나오면 분리
while(p!=NULL){
list[count]->index = count;
if(tokcount==0){
int num = atoi(p);
list[count]->number = num;
tokcount++;
}
else if(tokcount==1){
strcpy(list[count]->name, p);
//printf("%s ", list[count]->name);
tokcount++;
}
else if(tokcount==2){
int num = atoi(p);
list[count]->localnum = num;
//printf("%d ", list[count]->localnum);
tokcount++;
}
else if(tokcount==3){
strcpy(list[count]->localName, p);
//printf("%s ", list[count]->localName);
tokcount++;
}
else if(tokcount==4){
strcpy(list[count]->address, p);
//printf("%s ", list[count]->address);
tokcount++;
}
else if(tokcount==5){
strcpy(list[count]->hollyday, p);
//printf("%s ", list[count]->hollyday);
tokcount++;
}
else if(tokcount==6){
strcpy(list[count]->callnum, p);
list[count]->callnum[(strlen(list[count]->callnum)-1)]='\0';
//printf("%s\n", list[count]->callnum);
tokcount++;
}
//printf("%s", p);
p = strtok(NULL, ",");
}
count++;
}
}
}
return count;
}
void SaveData(library *list[], int count){// 파일 저장 함수
FILE *fi;
fi = fopen("Library_Info.csv", "w");
fprintf(fi, "도서관 일련번호,도서관명,구 코드,구명,주소,정기 휴관일,전화번호\n");
for(int i=0;i<count;i++){// 삭제된것 제외 파일 저장
if(list[i]->index== -1) continue;
if(i==count-1) {
fprintf(fi,"%d,%s,%d,%s,%s,%s,%s",list[i]->number,list[i]->name,list[i]->localnum,list[i]->localName,list[i]->address,list[i]->hollyday,list[i]->callnum);
}else{
fprintf(fi,"%d,%s,%d,%s,%s,%s,%s\n",list[i]->number,list[i]->name,list[i]->localnum,list[i]->localName,list[i]->address,list[i]->hollyday,list[i]->callnum);
}
}
printf("!저장되었습니다!\n");
fclose(fi);
}
void Recommendation(library *list[], int count){
int num;
num = rand()%count;
printf("오늘의 추천 도서관은 %s입니다!\n위치 : %s\n휴일 : %s\n", list[num]->name, list[num]->address, list[num]->hollyday);
}