-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter06.c
More file actions
64 lines (57 loc) · 1.54 KB
/
Copy pathChapter06.c
File metadata and controls
64 lines (57 loc) · 1.54 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
#include <stdio.h>
#include <string.h>
struct phone {
char name[20];
char number[20];
int age;
};
void phone_sort(int);
void phone_print(int);
void call(int n);
struct phone table[10];
int main()
{
int count;
printf("등록할 정보 입력(최대 10명)\n");
printf("그만입력하려면 0 입력\n");
call(10);
phone_sort(count);
phone_print(count);
return 0;
}
void phone_sort(int count)
{
int i, j;
struct phone temp;
for (i = 0; i < count - 1; i++)
for (j = i + 1; j < count; j++)
if (strcmp(table[i].name, table[j].name) == 1)
{
temp = table[i];
table[i] = table[j];
table[j] = temp;
}
}
void phone_print(int count)
{
int i;
printf("\n---------------------------------\n");
printf("%8s %16s %6s\n", "이름", "전화번호", "나이");
printf("---------------------------------\n");
for (i = 0; i < count; i++)
printf("%8s %16s %6d\n", table[i].name, table[i].number, table[i].age);
printf("---------------------------------\n\n");
}
void call(int n) {
if(n == 0) return;
printf("이름 입력 : ");
scanf("%s", table[n].name, sizeof(table[n].name));
if (strcmp(table[n].name, "0") == 0)
return;
printf("전화번호 입력 : ");
scanf("%s", table[n].number, sizeof(table[n].number));
printf("나이 입력 : ");
scanf("%d", &table[n].age);
fflush(stdin);
call(n-1);
}