回答編集履歴
1
ソース追記
test
CHANGED
@@ -1 +1,89 @@
|
|
1
1
|
直接の回答ではありませんが、[平均値プログラムsscanfの返り値で](https://teratail.com/questions/140350)のBAを参考にされたらどうでしょう?
|
2
|
+
|
3
|
+
[追記]
|
4
|
+
|
5
|
+
sscanf()を使わなければ、こんな方法も有りますd^^
|
6
|
+
|
7
|
+
```c
|
8
|
+
|
9
|
+
usr~/test/c % cat ct0.c
|
10
|
+
|
11
|
+
#include <stdio.h>
|
12
|
+
|
13
|
+
#include <stdlib.h>
|
14
|
+
|
15
|
+
//
|
16
|
+
|
17
|
+
int read(void);
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
int main(void)
|
22
|
+
|
23
|
+
{
|
24
|
+
|
25
|
+
printf("カウンタ=%d\n", read());
|
26
|
+
|
27
|
+
//
|
28
|
+
|
29
|
+
return 0;
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
|
35
|
+
*/
|
36
|
+
|
37
|
+
int read(void)
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
int siz = 0;
|
42
|
+
|
43
|
+
char *ptr = 0;
|
44
|
+
|
45
|
+
char buf[1024];
|
46
|
+
|
47
|
+
//
|
48
|
+
|
49
|
+
if (fgets(buf, sizeof buf, stdin) != NULL) {
|
50
|
+
|
51
|
+
siz = (int)strtol(buf, &ptr, 10);
|
52
|
+
|
53
|
+
for (int i = 0; i < siz; i++) {
|
54
|
+
|
55
|
+
int n = (int)strtol(ptr, &ptr, 10);
|
56
|
+
|
57
|
+
printf("%d\n", n);
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
//
|
64
|
+
|
65
|
+
return siz;
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
//
|
70
|
+
|
71
|
+
usr~/test/c % ./a.out
|
72
|
+
|
73
|
+
4 1 2 3 4
|
74
|
+
|
75
|
+
1
|
76
|
+
|
77
|
+
2
|
78
|
+
|
79
|
+
3
|
80
|
+
|
81
|
+
4
|
82
|
+
|
83
|
+
カウンタ=4
|
84
|
+
|
85
|
+
usr~/test/c %
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```
|