-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.c
More file actions
76 lines (65 loc) · 1.73 KB
/
manager.c
File metadata and controls
76 lines (65 loc) · 1.73 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
#include "manager.h"
int selectMenu(){
int menu;
printf("\n*** 제품 관리 ***\n");
printf("1. 조회\n");
printf("2. 추가\n");
printf("3. 수정\n");
printf("4. 삭제\n");
printf("5. 저장\n");
printf("0. 종료\n\n");
printf("=> 원하는 메뉴는? ");
scanf("%d", &menu);
return menu;
}
void listProduct(Product *p,int count){
printf("\nNo. Name weight price\n");
printf("================================\n");
for(int i=0; i<count; i++){
if( p[i].weight == -1 || p[i].price == -1 ) continue;
printf("%2d.", i+1);
readProduct(&p[i]);
}
printf("\n");
}
int selectDataNo(Product *p, int count){
int no;
listProduct(p,count);
printf("번호는 (취소:0)?");
scanf("%d",&no);
getchar();
return no;
}
//배열데이터를 파일에 저장하는 함수
void saveData(Product p[], int count){
FILE* fp;
//중량 가격 제품명
fp= fopen("product.txt","wt");
if(fp == NULL){
printf("파일이 존재하지 않아서 열 수가 없습니다!\n");
return;
}
for(int i=0; i<count; i++){
fprintf(fp, "%s %d %d\n", p[i].name, p[i].weight, p[i].price);
}
fclose(fp);
printf("저장됨!\n");
}
//파일에서 데이터 불러오는 함수
int loadData(Product *p){
int count=0;
FILE*fp;
//파일 내용을 읽어와서 배열에 값 추가하기
fp = fopen("product.txt", "rt");
if(fp == NULL){
printf("파일 여는 것을 실패했습니다!\n");
return 0;
}
while(!feof(fp)){
fscanf(fp, "%s %d %d", p[count].name, &p[count].weight, &p[count].price);
count++;
}
fclose(fp);
printf("=> 로딩 성공!\n");
return count-1;
}