質問編集履歴
5
codeの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -110,6 +110,4 @@
|
|
110
110
|
|
111
111
|
return 0;
|
112
112
|
}
|
113
|
-
|
114
|
-
|
115
113
|
```
|
4
hファイル、mainファイルの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -59,11 +59,8 @@
|
|
59
59
|
void string_sort(int n, char (*a)[STRLEN+1]);
|
60
60
|
|
61
61
|
|
62
|
-
|
62
|
+
main.cファイル↓
|
63
|
-
|
64
|
-
```
|
63
|
+
```c
|
65
|
-
|
66
|
-
str_sort_main.c```c
|
67
64
|
#include <stdio.h>
|
68
65
|
#include <string.h>
|
69
66
|
#include <assert.h>
|
3
hファイルとメインの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -49,4 +49,70 @@
|
|
49
49
|
}
|
50
50
|
}
|
51
51
|
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
str_sort.hファイル↓
|
56
|
+
```c
|
57
|
+
#define STRLEN 63
|
58
|
+
#define STRFMT "%63s"
|
59
|
+
void string_sort(int n, char (*a)[STRLEN+1]);
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
```
|
65
|
+
|
66
|
+
str_sort_main.c```c
|
67
|
+
#include <stdio.h>
|
68
|
+
#include <string.h>
|
69
|
+
#include <assert.h>
|
70
|
+
#include "str_sort.h"
|
71
|
+
#define MAX_N 64
|
72
|
+
|
73
|
+
|
74
|
+
int str_array_scan(record_t a[])
|
75
|
+
{
|
76
|
+
int i;
|
77
|
+
int n;
|
78
|
+
fprintf(stderr, "n = ");
|
79
|
+
scanf("%d",&n);
|
80
|
+
assert(n<=MAX_N);
|
81
|
+
for (i=0; i<n; i++) {
|
82
|
+
fprintf(stderr, "[%d].name : ", i);
|
83
|
+
scanf(STRFMT, a[i].name);
|
84
|
+
fprintf(stderr, "[%d].age : ", i);
|
85
|
+
scanf("%d", &a[i].age);
|
86
|
+
fprintf(stderr, "[%d].height : ", i);
|
87
|
+
scanf("%lf", &a[i].height);
|
88
|
+
}
|
89
|
+
return n;
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
void str_array_print(int n, record_t a[])
|
94
|
+
{
|
95
|
+
int i;
|
96
|
+
for (i=0; i<n; i++) {
|
97
|
+
printf("%-10s", a[i].name);
|
98
|
+
printf("%3d", a[i].age);
|
99
|
+
printf("%7.2f", a[i].height);
|
100
|
+
printf("\n");
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
|
105
|
+
int main(void)
|
106
|
+
{
|
107
|
+
int n;
|
108
|
+
record_t a[MAX_N];
|
109
|
+
|
110
|
+
n = str_array_scan(a);
|
111
|
+
str_sort(n, a);
|
112
|
+
str_array_print(n, a);
|
113
|
+
|
114
|
+
return 0;
|
115
|
+
}
|
116
|
+
|
117
|
+
|
52
118
|
```
|
2
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
と表示するようにしたい。
|
22
22
|
|
23
23
|
|
24
|
+
```c
|
24
25
|
#include<stdio.h>
|
25
26
|
#include<string.h>
|
26
27
|
#include "str_sort.h"
|
@@ -47,6 +48,5 @@
|
|
47
48
|
a[j] = min;
|
48
49
|
}
|
49
50
|
}
|
50
|
-
|
51
|
+
|
51
|
-
コード
|
52
52
|
```
|
1
コードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,4 +18,35 @@
|
|
18
18
|
yamamoto 22 177.40
|
19
19
|
nakamura 22 179.70
|
20
20
|
|
21
|
-
と表示するようにしたい。
|
21
|
+
と表示するようにしたい。
|
22
|
+
|
23
|
+
|
24
|
+
#include<stdio.h>
|
25
|
+
#include<string.h>
|
26
|
+
#include "str_sort.h"
|
27
|
+
|
28
|
+
void srt_sort(int n, record_t *a){
|
29
|
+
|
30
|
+
int i, j, k;
|
31
|
+
record_t min;
|
32
|
+
|
33
|
+
for(k = 0; k <= n - 2; k++){
|
34
|
+
|
35
|
+
for(i = k, j = k, min = a[k]; i < n; i++){
|
36
|
+
|
37
|
+
if(min < a[i]){
|
38
|
+
|
39
|
+
min = a[i];
|
40
|
+
|
41
|
+
j = i;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
min = a[k];
|
46
|
+
a[k] = a[j];
|
47
|
+
a[j] = min;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
```c
|
51
|
+
コード
|
52
|
+
```
|