質問編集履歴

7

間違いを訂正

2020/08/31 23:44

投稿

Merrifield
Merrifield

スコア31

test CHANGED
File without changes
test CHANGED
@@ -78,6 +78,8 @@
78
78
 
79
79
  エラーコード
80
80
 
81
+ ```ここに言語を入力
82
+
81
83
  solution.c:9:38: warning: 'sizeof source' will return the size of the pointer, not the array itself [-Wsizeof-pointer-div]
82
84
 
83
85
  for(n = 0; n < (int)(sizeof source / sizeof source[0]); n++)
@@ -101,6 +103,8 @@
101
103
  3 warnings generated.
102
104
 
103
105
  2 warnings and 6 errors generated.
106
+
107
+ ```
104
108
 
105
109
 
106
110
 
@@ -170,6 +174,8 @@
170
174
 
171
175
  修正版のエラー
172
176
 
177
+ ```ここに言語を入力
178
+
173
179
  solution.c:27:11: warning: address of stack memory associated with local variable 'str1' returned [-Wreturn-stack-address]
174
180
 
175
181
  return str1;
@@ -177,3 +183,5 @@
177
183
  ^~~~
178
184
 
179
185
  1 warning generated.
186
+
187
+ ```

6

間違いの訂正

2020/08/31 23:44

投稿

Merrifield
Merrifield

スコア31

test CHANGED
File without changes
test CHANGED
@@ -128,7 +128,7 @@
128
128
 
129
129
 
130
130
 
131
- for(n = 0; n < strlen(source); n++)
131
+ for(n = 0; n < (int)strlen(source); n++)
132
132
 
133
133
  {
134
134
 
@@ -142,7 +142,7 @@
142
142
 
143
143
  {
144
144
 
145
- for(int m =0; m < n; m++)
145
+ for(int m = 0; m < n; m++)
146
146
 
147
147
  {
148
148
 

5

間違いの訂正

2020/08/31 13:34

投稿

Merrifield
Merrifield

スコア31

test CHANGED
File without changes
test CHANGED
@@ -20,6 +20,10 @@
20
20
 
21
21
  #include <string.h>
22
22
 
23
+ #include <stdio.h>
24
+
25
+
26
+
23
27
  char *accum(const char *source)
24
28
 
25
29
  {
@@ -32,7 +36,7 @@
32
36
 
33
37
 
34
38
 
35
- for(n = 0; n < (int)(sizeof source / sizeof source[0]); n++)
39
+ for(n = 0; n < (int)strlen(source); n++)
36
40
 
37
41
  {
38
42
 
@@ -172,8 +176,4 @@
172
176
 
173
177
  ^~~~
174
178
 
175
- solution.c:11:16: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
176
-
177
- for(n = 0; n < strlen(source); n++)
178
-
179
- ~ ^ ~~~~~~~~~~~~~~
179
+ 1 warning generated.

4

間違いの訂正

2020/08/31 13:28

投稿

Merrifield
Merrifield

スコア31

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- 下の例の通りの関数を作りたいと思っています。sizeofのあたりやsprintfの箇所が問題があるだと思ます、どうおしいのか分からないので、教えてください。
1
+ 下の例の通りの関数を作りたいと思っています。returnの箇所の間違いがからないので、教えてください。
2
2
 
3
3
 
4
4
 

3

間違いの訂正

2020/08/31 13:27

投稿

Merrifield
Merrifield

スコア31

test CHANGED
File without changes
test CHANGED
@@ -13,6 +13,8 @@
13
13
 
14
14
 
15
15
  ```c
16
+
17
+
16
18
 
17
19
  #include <ctype.h>
18
20
 
@@ -98,7 +100,9 @@
98
100
 
99
101
 
100
102
 
103
+ 修正版
104
+
101
- 修正版```c
105
+ ```c
102
106
 
103
107
  #include <ctype.h>
104
108
 

2

間違いの訂正

2020/08/31 13:24

投稿

Merrifield
Merrifield

スコア31

test CHANGED
File without changes
test CHANGED
@@ -95,3 +95,81 @@
95
95
  3 warnings generated.
96
96
 
97
97
  2 warnings and 6 errors generated.
98
+
99
+
100
+
101
+ 修正版```c
102
+
103
+ #include <ctype.h>
104
+
105
+ #include <string.h>
106
+
107
+ #include <stdio.h>
108
+
109
+
110
+
111
+ char *accum(const char *source)
112
+
113
+ {
114
+
115
+ int n;
116
+
117
+ char str1[255];
118
+
119
+ char a = '-';
120
+
121
+
122
+
123
+ for(n = 0; n < strlen(source); n++)
124
+
125
+ {
126
+
127
+
128
+
129
+ sprintf(str1,"%c",toupper(source[n]));
130
+
131
+
132
+
133
+ if(n > 0)
134
+
135
+ {
136
+
137
+ for(int m =0; m < n; m++)
138
+
139
+ {
140
+
141
+ sprintf(str1,"%c",tolower(source[n]));
142
+
143
+ }
144
+
145
+ }
146
+
147
+
148
+
149
+ sprintf(str1,"%c",a);
150
+
151
+ }
152
+
153
+
154
+
155
+ return str1;
156
+
157
+ }
158
+
159
+ ```
160
+
161
+
162
+
163
+ 修正版のエラー
164
+
165
+ solution.c:27:11: warning: address of stack memory associated with local variable 'str1' returned [-Wreturn-stack-address]
166
+
167
+ return str1;
168
+
169
+ ^~~~
170
+
171
+ solution.c:11:16: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
172
+
173
+ for(n = 0; n < strlen(source); n++)
174
+
175
+ ~ ^ ~~~~~~~~~~~~~~

1

間違いの訂正

2020/08/31 13:22

投稿

Merrifield
Merrifield

スコア31

test CHANGED
File without changes
test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  int n;
26
26
 
27
- char *str1;
27
+ char str1[255];
28
28
 
29
29
  char a = '-';
30
30
 
@@ -36,7 +36,7 @@
36
36
 
37
37
 
38
38
 
39
- sprintf(str1,%c,toupper(source[n]));
39
+ sprintf(str1,"%c",toupper(source[n]));
40
40
 
41
41
 
42
42
 
@@ -48,7 +48,7 @@
48
48
 
49
49
  {
50
50
 
51
- sprintf(str1,%c,tolower(source[n]));
51
+ sprintf(str1,"%c",tolower(source[n]));
52
52
 
53
53
  }
54
54
 
@@ -56,7 +56,7 @@
56
56
 
57
57
 
58
58
 
59
- sprintf(str1,%c,a);
59
+ sprintf(str1,"%c",a);
60
60
 
61
61
  }
62
62
 
@@ -80,46 +80,18 @@
80
80
 
81
81
  solution.c:12:5: warning: implicitly declaring library function 'sprintf' with type 'int (char *, const char *, ...)' [-Wimplicit-function-declaration]
82
82
 
83
- sprintf(str1,%c,toupper(source[n]));
83
+ sprintf(str1,"%c",toupper(source[n]));
84
84
 
85
85
  ^
86
86
 
87
87
  solution.c:12:5: note: include the header <stdio.h> or explicitly provide a declaration for 'sprintf'
88
88
 
89
- solution.c:12:18: error: expected expression
89
+ solution.c:25:11: warning: address of stack memory associated with local variable 'str1' returned [-Wreturn-stack-address]
90
90
 
91
- sprintf(str1,%c,toupper(source[n]));
91
+ return str1;
92
92
 
93
- ^
93
+ ^~~~
94
94
 
95
- solution.c:12:19: error: use of undeclared identifier 'c'
96
-
97
- sprintf(str1,%c,toupper(source[n]));
98
-
99
- ^
100
-
101
- solution.c:18:22: error: expected expression
102
-
103
- sprintf(str1,%c,tolower(source[n]));
104
-
105
- ^
106
-
107
- solution.c:18:23: error: use of undeclared identifier 'c'
108
-
109
- sprintf(str1,%c,tolower(source[n]));
110
-
111
- ^
112
-
113
- solution.c:22:22: error: expected expression
114
-
115
- sprintf(str1,%c,a);
95
+ 3 warnings generated.
116
-
117
- ^
118
-
119
- solution.c:22:23: error: use of undeclared identifier 'c'
120
-
121
- sprintf(str1,%c,a);
122
-
123
- ^
124
96
 
125
97
  2 warnings and 6 errors generated.