回答編集履歴

2

aa

2017/07/09 03:47

投稿

mpyw
mpyw

スコア5223

test CHANGED
@@ -30,6 +30,8 @@
30
30
 
31
31
  scanf("%*c");
32
32
 
33
+ printf("Output: %d\n", buffer);
34
+
33
35
 
34
36
 
35
37
  printf("Input: ");
@@ -42,9 +44,9 @@
42
44
 
43
45
  scanf("%*c");
44
46
 
47
+ printf("Output: %d\n", buffer);
45
48
 
46
49
 
47
- printf("Output: %d\n", buffer);
48
50
 
49
51
  return 0;
50
52
 

1

aa

2017/07/09 03:47

投稿

mpyw
mpyw

スコア5223

test CHANGED
@@ -6,4 +6,52 @@
6
6
 
7
7
 
8
8
 
9
+ ```c
10
+
11
+ #include <stdio.h>
12
+
13
+
14
+
15
+ int main(void)
16
+
17
+ {
18
+
19
+ int num;
20
+
21
+
22
+
23
+ printf("Input: ");
24
+
9
- `"%d"` の代わりに `"%d%*[^\n]"` を使ってみてください。
25
+ if (scanf("%d%*[^\n]", &num) != 1) {
26
+
27
+ return 1;
28
+
29
+ }
30
+
31
+ scanf("%*c");
32
+
33
+
34
+
35
+ printf("Input: ");
36
+
37
+ if (scanf("%d%*[^\n]", &num) != 1) {
38
+
39
+ return 1;
40
+
41
+ }
42
+
43
+ scanf("%*c");
44
+
45
+
46
+
47
+ printf("Output: %d\n", buffer);
48
+
49
+ return 0;
50
+
51
+ }
52
+
53
+ ```
54
+
55
+
56
+
57
+ この方法を試してみてください。2回目の整数読み取りも正しく動作するはずです。