回答編集履歴

2

微修正

2020/05/20 08:19

投稿

episteme
episteme

スコア16614

test CHANGED
@@ -11,8 +11,6 @@
11
11
  #include <stdio.h>
12
12
 
13
13
  #include <string.h>
14
-
15
- #include <stdbool.h>
16
14
 
17
15
 
18
16
 

1

追記

2020/05/20 08:19

投稿

episteme
episteme

スコア16614

test CHANGED
@@ -54,6 +54,64 @@
54
54
 
55
55
  }
56
56
 
57
+ ```
57
58
 
58
59
 
60
+
61
+ [追記] 1返したらアカンやろ! バージョン:
62
+
63
+ ```C
64
+
65
+ // VC++ : C3861 抑止
66
+
67
+ #define _CRT_SECURE_NO_WARNINGS
68
+
69
+
70
+
71
+ #include <stdio.h>
72
+
73
+ #include <string.h>
74
+
75
+ #include <stdbool.h>
76
+
77
+
78
+
79
+ bool input_int(int* result, const char* prompt, const char* bad_message) {
80
+
81
+ while (1) {
82
+
83
+ char buf[1024];
84
+
85
+ if ( prompt ) printf("%s", prompt);
86
+
87
+ if (fgets(buf, sizeof buf, stdin) == NULL) return false;
88
+
89
+ char c;
90
+
91
+ if (sscanf(buf, "%d %c", result, &c) == 1) break;
92
+
93
+ if ( bad_message ) puts(bad_message);
94
+
95
+ }
96
+
97
+ return true;
98
+
99
+ }
100
+
101
+
102
+
103
+ int main(void) {
104
+
105
+ int n;
106
+
107
+ if ( input_int(&n, "整数値入れてネ: ", "ダメ。やりなおし!") ) {
108
+
109
+ printf("%d を入力してくれてアリガト\n", n);
110
+
111
+ }
112
+
113
+ return 0;
114
+
115
+ }
116
+
59
117
  ```