回答編集履歴
1
<string.h> などの修正
answer
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
こんなコードはいかがでしょうか?
|
2
2
|
```C
|
3
|
-
#include <stdio.h>
|
3
|
+
#include <stdio.h> // scanf, puts
|
4
|
-
#include <
|
4
|
+
#include <string.h> // strlen
|
5
5
|
|
6
6
|
#define STR_SIZE 1000
|
7
7
|
#define BUF_SIZE 20
|
@@ -10,13 +10,16 @@
|
|
10
10
|
int main(void)
|
11
11
|
{
|
12
12
|
char str[STR_SIZE];
|
13
|
-
int n
|
13
|
+
int n;
|
14
14
|
if (scanf("%d", &n) != 1) return 1;
|
15
|
-
for (int i = 0
|
15
|
+
for (int i = 0, j = 0; i < n; i++) {
|
16
|
+
if (j >= STR_SIZE - BUF_SIZE) return 2;
|
16
17
|
if (i > 0) str[j++] = '_';
|
17
18
|
scanf(fmt, str + j);
|
18
19
|
j += strlen(str + j);
|
19
20
|
}
|
20
21
|
puts(str);
|
21
22
|
}
|
22
|
-
```
|
23
|
+
```
|
24
|
+
**追記**
|
25
|
+
<string.h> など、ちょっと修正しました。
|