回答編集履歴
3
変更
answer
CHANGED
@@ -13,15 +13,16 @@
|
|
13
13
|
|
14
14
|
if (count > 2) {
|
15
15
|
str_a=malloc(strlen(param[1])+1);
|
16
|
+
str_b=param[2];
|
16
17
|
memcpy(str_a,param[1],strlen(param[1])+1);
|
17
|
-
str_b=param[2];
|
18
18
|
} else {
|
19
19
|
printf("It is not enough that parameter which you proposed.");
|
20
20
|
exit(2);
|
21
21
|
}
|
22
22
|
char* res = NULL;
|
23
|
-
|
23
|
+
printf("%s", my_strconcat(str_a, str_b));
|
24
|
+
|
24
|
-
|
25
|
+
free(str_a);
|
25
26
|
return(0);
|
26
27
|
}
|
27
28
|
|
@@ -30,11 +31,11 @@
|
|
30
31
|
char* source_p = NULL;
|
31
32
|
int len_a = 0;
|
32
33
|
int len_b = 0;
|
34
|
+
|
33
35
|
len_a = strlen(a);
|
34
36
|
len_b = strlen(b);
|
37
|
+
temp = realloc(a, len_a + len_b);
|
35
38
|
|
36
|
-
temp = realloc(a, len_a + len_b +1);
|
37
|
-
|
38
39
|
if (temp == a) {
|
39
40
|
source_p = a;
|
40
41
|
} else {
|
@@ -45,17 +46,12 @@
|
|
45
46
|
// \0を示すインデックスまでポインタを進める
|
46
47
|
a += len_a;
|
47
48
|
|
48
|
-
while(1) {
|
49
|
-
|
49
|
+
while(*b != '\0') {
|
50
|
-
|
50
|
+
*a = *b; // (1)ここで第一引数のポインタ変数に第二引数の文字を代入(コピー)して文字列を拡張
|
51
|
-
|
51
|
+
a++;
|
52
|
-
|
52
|
+
b++;
|
53
|
-
} else {
|
54
|
-
break;
|
55
|
-
}
|
56
53
|
}
|
57
|
-
*a =
|
54
|
+
*a = *b;
|
58
|
-
// free(a);
|
59
55
|
return (source_p);
|
60
56
|
}
|
61
57
|
```
|
2
変更
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
パラメータの領域は直接上位のアドレスを指していますのでreallocするとエラーになると思います。ですので
|
1
|
+
パラメータの領域は直接上位のアドレスを指していますのでreallocするとエラーになると思います。ですのでrealloc用に領域を確保します。
|
2
2
|
```c
|
3
3
|
#include <stdio.h>
|
4
4
|
#include <stdlib.h>
|
1
変更
answer
CHANGED
@@ -12,8 +12,8 @@
|
|
12
12
|
char* str_b = NULL;
|
13
13
|
|
14
14
|
if (count > 2) {
|
15
|
-
str_a=malloc(strlen(param[1]));
|
15
|
+
str_a=malloc(strlen(param[1])+1);
|
16
|
-
memcpy(str_a,param[1],strlen(param[1]));
|
16
|
+
memcpy(str_a,param[1],strlen(param[1])+1);
|
17
17
|
str_b=param[2];
|
18
18
|
} else {
|
19
19
|
printf("It is not enough that parameter which you proposed.");
|