回答編集履歴

3

編集

2017/05/28 07:11

投稿

kyunta
kyunta

スコア350

test CHANGED
@@ -1,3 +1,11 @@
1
+ ```ここに言語を入力
2
+
3
+ while(text[t]!='\0'&& insert[i] !='\0'){ //両方ともナルになるまで繰り返す
4
+
5
+ ```
6
+
7
+ これを
8
+
1
9
  ```ここに言語を入力
2
10
 
3
11
  while (text[t] != '\0' || insert[i] != '\0') { //どちらかが\0でない間

2

編集

2017/05/28 07:11

投稿

kyunta
kyunta

スコア350

test CHANGED
@@ -1,4 +1,14 @@
1
+ ```ここに言語を入力
2
+
3
+ while (text[t] != '\0' || insert[i] != '\0') { //どちらかが\0でない間
4
+
5
+ ```
6
+
7
+ これでOKだと思います。
8
+
9
+
10
+
1
- 一応、動くものに変更。エラー処理などは入れていませんので参考までに。
11
+ 一応、別で動くもの。エラー処理などは入れていませんので参考までに。
2
12
 
3
13
 
4
14
 

1

編集

2017/05/28 07:07

投稿

kyunta
kyunta

スコア350

test CHANGED
@@ -1,9 +1,81 @@
1
- ```ここに言語を入力
2
-
3
- while (text[t] != '\0') { //\0になまで繰り返す
1
+ 一応、動くもの変更。エラー処理どは入れていせんの参考までに。
4
-
5
- ```
6
2
 
7
3
 
8
4
 
5
+ ```ここに言語を入力
6
+
7
+ int index = 0;
8
+
9
+ char text[] = "love";
10
+
11
+ char insert[100] = { '\0' };
12
+
13
+ char join[100] = { '\0' };
14
+
15
+
16
+
17
+ int t = 0;
18
+
19
+ int i = 0;
20
+
21
+ int j = 0;
22
+
23
+
24
+
25
+ printf("文字列:%s\n", text);
26
+
27
+ printf("挿入文字列:");
28
+
29
+ scanf("%s", &insert);
30
+
31
+
32
+
33
+ printf("\n挿入位置:");
34
+
35
+ scanf("%d", &index);
36
+
37
+
38
+
39
+ while (text[t] != '\0') {
40
+
41
+ if (index == t) {
42
+
43
+ while (insert[i] != '\0') {
44
+
45
+ join[j] = insert[i];
46
+
47
+ ++i;
48
+
49
+ ++j;
50
+
51
+ }
52
+
53
+ }else if((t+1) == 4){
54
+
9
- この修正だけで一応いけると思います。
55
+ join[j] = text[t];
56
+
57
+ while (insert[i] != '\0') {
58
+
59
+ join[++j] = insert[i++];
60
+
61
+ }
62
+
63
+ }
64
+
65
+ if(t < 3 || index <= t) {
66
+
67
+ join[j] = text[t];
68
+
69
+ }
70
+
71
+ ++t;
72
+
73
+ ++j;
74
+
75
+ }
76
+
77
+ join[j] = '\0';
78
+
79
+ printf("\n挿入結果:%s \n", join);
80
+
81
+ ```