-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddressbook.c
More file actions
159 lines (109 loc) · 2.85 KB
/
addressbook.c
File metadata and controls
159 lines (109 loc) · 2.85 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
#include <stdio.h>
#include<string.h>
/*
//정수 타입 선언
typedef char int8;
typedef short int16;
typedef int int32;
typedef long int64;
//양의 정수 타입 선언(0을 포함한)
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long uint64;
//실수 타입 선언
typedef float f32;
typedef double f64;
*/
int numberOfUser = 3;
typedef struct {
char name[30];
char phone[30];
}ADDRESS;
int displayNumberByArray (ADDRESS info[], int numOfDis)
{
printf("----연락처----\n");
printf("이름 | 전화번호\n");
for(int i=0; i<numOfDis; i++){
printf("%s: %s\n",info[i].name, info[i].phone);
}
}
int displayNumberByPointer (ADDRESS *info)
{
for(int i=0; i<3; i++){
printf("%s: %s\n",(info+i)->name, (info+i)->phone);
}
}
int addUser(ADDRESS AddrInfo[], int i){
int result;
char cmd[10];
char name[20];
char phone[20];
printf("이름을 입력하세요: ");
scanf("%s", &name );
printf("전화번호를 입력하세요: ");
scanf("%s", &phone);
printf("등록을 하시겠습니까? (yes/no) ");
scanf("%s", &cmd);
if( strcmp(cmd, "yes") == 0){
strcpy(AddrInfo[i].name, name);
strcpy(AddrInfo[i].phone, phone);
printf("등록완료되었습니다.\n");
result = 1;
}
else{
printf("취소 되었습니다. \n");
result =0;
}
return result;
}
int main()
{
int cmd;
ADDRESS addr[100]={{"김유림", "01066431234" },
{"김유빈", "0106643568" },
{"김나선", "01056781234" },
};
displayNumberByArray(addr,numberOfUser);
//displayNumberByPointer(&addr);
//printf("연락처를 등록하시겠습니까?(yes/no) \n");
int result;
while(1){
printf("\n \n ---메뉴를 선택하세요---\n");
printf("1: 연락처 추가 \n");
printf("2: 검색 \n");
printf("3: 삭제 \n");
printf("4: 연락처 표시 \n");
printf("0: 프로그램 종료 \n");
scanf("%d", &cmd );
if( cmd == 1 ){
//등록하는 함수를 호출 한다.
result = addUser(addr, numberOfUser);
if( result == 1)
{
numberOfUser++;
}
}
else if( cmd == 2 ){
//검색하는 함수를 호출 한다. ** strcmp 로 순차적(선형) 검색해서 결과를 알려준다.
}
else if( cmd == 3 ){
//삭제하는 함수를 호출 한다.
}
else if (cmd == 4){
displayNumberByArray(addr,numberOfUser);
}
else if( cmd == 0 ){
//프로그램을 종료한다.
break;
}
else{
printf("잘못된 명령을 입력하였습니다. 다시 선택해 주세요.\n");
}
}
return 0;
}
//연락처 검색
void search(){
int phone=0;
}