回答編集履歴
2
aa
answer
CHANGED
|
@@ -14,14 +14,15 @@
|
|
|
14
14
|
return 1;
|
|
15
15
|
}
|
|
16
16
|
scanf("%*c");
|
|
17
|
+
printf("Output: %d\n", buffer);
|
|
17
18
|
|
|
18
19
|
printf("Input: ");
|
|
19
20
|
if (scanf("%d%*[^\n]", &num) != 1) {
|
|
20
21
|
return 1;
|
|
21
22
|
}
|
|
22
23
|
scanf("%*c");
|
|
24
|
+
printf("Output: %d\n", buffer);
|
|
23
25
|
|
|
24
|
-
printf("Output: %d\n", buffer);
|
|
25
26
|
return 0;
|
|
26
27
|
}
|
|
27
28
|
```
|
1
aa
answer
CHANGED
|
@@ -2,4 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
- [標準入力から安全に文字列を受け取る方法いろいろ - Qiita](http://qiita.com/mpyw/items/aff12a6ff2c7726ed1d8#scanf%E3%81%AE%E5%88%A9%E7%94%A8-1)
|
|
4
4
|
|
|
5
|
+
```c
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
|
|
8
|
+
int main(void)
|
|
9
|
+
{
|
|
10
|
+
int num;
|
|
11
|
+
|
|
12
|
+
printf("Input: ");
|
|
5
|
-
|
|
13
|
+
if (scanf("%d%*[^\n]", &num) != 1) {
|
|
14
|
+
return 1;
|
|
15
|
+
}
|
|
16
|
+
scanf("%*c");
|
|
17
|
+
|
|
18
|
+
printf("Input: ");
|
|
19
|
+
if (scanf("%d%*[^\n]", &num) != 1) {
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
scanf("%*c");
|
|
23
|
+
|
|
24
|
+
printf("Output: %d\n", buffer);
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
この方法を試してみてください。2回目の整数読み取りも正しく動作するはずです。
|