teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

7

間違いを訂正

2020/08/31 23:44

投稿

Merrifield
Merrifield

スコア31

title CHANGED
File without changes
body CHANGED
@@ -38,6 +38,7 @@
38
38
  ```
39
39
 
40
40
  エラーコード
41
+ ```ここに言語を入力
41
42
  solution.c:9:38: warning: 'sizeof source' will return the size of the pointer, not the array itself [-Wsizeof-pointer-div]
42
43
  for(n = 0; n < (int)(sizeof source / sizeof source[0]); n++)
43
44
  ~~~~~~~~~~~~~ ^
@@ -50,6 +51,7 @@
50
51
  ^~~~
51
52
  3 warnings generated.
52
53
  2 warnings and 6 errors generated.
54
+ ```
53
55
 
54
56
  修正版
55
57
  ```c
@@ -84,7 +86,9 @@
84
86
  ```
85
87
 
86
88
  修正版のエラー
89
+ ```ここに言語を入力
87
90
  solution.c:27:11: warning: address of stack memory associated with local variable 'str1' returned [-Wreturn-stack-address]
88
91
  return str1;
89
92
  ^~~~
90
- 1 warning generated.
93
+ 1 warning generated.
94
+ ```

6

間違いの訂正

2020/08/31 23:44

投稿

Merrifield
Merrifield

スコア31

title CHANGED
File without changes
body CHANGED
@@ -63,14 +63,14 @@
63
63
  char str1[255];
64
64
  char a = '-';
65
65
 
66
- for(n = 0; n < strlen(source); n++)
66
+ for(n = 0; n < (int)strlen(source); n++)
67
67
  {
68
68
 
69
69
  sprintf(str1,"%c",toupper(source[n]));
70
70
 
71
71
  if(n > 0)
72
72
  {
73
- for(int m =0; m < n; m++)
73
+ for(int m = 0; m < n; m++)
74
74
  {
75
75
  sprintf(str1,"%c",tolower(source[n]));
76
76
  }

5

間違いの訂正

2020/08/31 13:34

投稿

Merrifield
Merrifield

スコア31

title CHANGED
File without changes
body CHANGED
@@ -9,13 +9,15 @@
9
9
 
10
10
  #include <ctype.h>
11
11
  #include <string.h>
12
+ #include <stdio.h>
13
+
12
14
  char *accum(const char *source)
13
15
  {
14
16
  int n;
15
17
  char str1[255];
16
18
  char a = '-';
17
19
 
18
- for(n = 0; n < (int)(sizeof source / sizeof source[0]); n++)
20
+ for(n = 0; n < (int)strlen(source); n++)
19
21
  {
20
22
 
21
23
  sprintf(str1,"%c",toupper(source[n]));
@@ -85,6 +87,4 @@
85
87
  solution.c:27:11: warning: address of stack memory associated with local variable 'str1' returned [-Wreturn-stack-address]
86
88
  return str1;
87
89
  ^~~~
88
- solution.c:11:16: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
89
- for(n = 0; n < strlen(source); n++)
90
- ~ ^ ~~~~~~~~~~~~~~
90
+ 1 warning generated.

4

間違いの訂正

2020/08/31 13:28

投稿

Merrifield
Merrifield

スコア31

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

3

間違いの訂正

2020/08/31 13:27

投稿

Merrifield
Merrifield

スコア31

title CHANGED
File without changes
body CHANGED
@@ -6,6 +6,7 @@
6
6
  accum("cwAt") -> "C-Ww-Aaa-Tttt"
7
7
 
8
8
  ```c
9
+
9
10
  #include <ctype.h>
10
11
  #include <string.h>
11
12
  char *accum(const char *source)
@@ -48,7 +49,8 @@
48
49
  3 warnings generated.
49
50
  2 warnings and 6 errors generated.
50
51
 
52
+ 修正版
51
- 修正版```c
53
+ ```c
52
54
  #include <ctype.h>
53
55
  #include <string.h>
54
56
  #include <stdio.h>

2

間違いの訂正

2020/08/31 13:24

投稿

Merrifield
Merrifield

スコア31

title CHANGED
File without changes
body CHANGED
@@ -46,4 +46,43 @@
46
46
  return str1;
47
47
  ^~~~
48
48
  3 warnings generated.
49
- 2 warnings and 6 errors generated.
49
+ 2 warnings and 6 errors generated.
50
+
51
+ 修正版```c
52
+ #include <ctype.h>
53
+ #include <string.h>
54
+ #include <stdio.h>
55
+
56
+ char *accum(const char *source)
57
+ {
58
+ int n;
59
+ char str1[255];
60
+ char a = '-';
61
+
62
+ for(n = 0; n < strlen(source); n++)
63
+ {
64
+
65
+ sprintf(str1,"%c",toupper(source[n]));
66
+
67
+ if(n > 0)
68
+ {
69
+ for(int m =0; m < n; m++)
70
+ {
71
+ sprintf(str1,"%c",tolower(source[n]));
72
+ }
73
+ }
74
+
75
+ sprintf(str1,"%c",a);
76
+ }
77
+
78
+ return str1;
79
+ }
80
+ ```
81
+
82
+ 修正版のエラー
83
+ solution.c:27:11: warning: address of stack memory associated with local variable 'str1' returned [-Wreturn-stack-address]
84
+ return str1;
85
+ ^~~~
86
+ solution.c:11:16: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
87
+ for(n = 0; n < strlen(source); n++)
88
+ ~ ^ ~~~~~~~~~~~~~~

1

間違いの訂正

2020/08/31 13:22

投稿

Merrifield
Merrifield

スコア31

title CHANGED
File without changes
body CHANGED
@@ -11,23 +11,23 @@
11
11
  char *accum(const char *source)
12
12
  {
13
13
  int n;
14
- char *str1;
14
+ char str1[255];
15
15
  char a = '-';
16
16
 
17
17
  for(n = 0; n < (int)(sizeof source / sizeof source[0]); n++)
18
18
  {
19
19
 
20
- sprintf(str1,%c,toupper(source[n]));
20
+ sprintf(str1,"%c",toupper(source[n]));
21
21
 
22
22
  if(n > 0)
23
23
  {
24
24
  for(int m =0; m < n; m++)
25
25
  {
26
- sprintf(str1,%c,tolower(source[n]));
26
+ sprintf(str1,"%c",tolower(source[n]));
27
27
  }
28
28
  }
29
29
 
30
- sprintf(str1,%c,a);
30
+ sprintf(str1,"%c",a);
31
31
  }
32
32
 
33
33
  return str1;
@@ -39,25 +39,11 @@
39
39
  for(n = 0; n < (int)(sizeof source / sizeof source[0]); n++)
40
40
  ~~~~~~~~~~~~~ ^
41
41
  solution.c:12:5: warning: implicitly declaring library function 'sprintf' with type 'int (char *, const char *, ...)' [-Wimplicit-function-declaration]
42
- sprintf(str1,%c,toupper(source[n]));
42
+ sprintf(str1,"%c",toupper(source[n]));
43
43
  ^
44
44
  solution.c:12:5: note: include the header <stdio.h> or explicitly provide a declaration for 'sprintf'
45
- solution.c:12:18: error: expected expression
46
- sprintf(str1,%c,toupper(source[n]));
47
- ^
48
- solution.c:12:19: error: use of undeclared identifier 'c'
45
+ solution.c:25:11: warning: address of stack memory associated with local variable 'str1' returned [-Wreturn-stack-address]
49
- sprintf(str1,%c,toupper(source[n]));
50
- ^
51
- solution.c:18:22: error: expected expression
52
- sprintf(str1,%c,tolower(source[n]));
53
- ^
54
- solution.c:18:23: error: use of undeclared identifier 'c'
55
- sprintf(str1,%c,tolower(source[n]));
56
- ^
57
- solution.c:22:22: error: expected expression
58
- sprintf(str1,%c,a);
46
+ return str1;
59
- ^
47
+ ^~~~
60
- solution.c:22:23: error: use of undeclared identifier 'c'
61
- sprintf(str1,%c,a);
48
+ 3 warnings generated.
62
- ^
63
49
  2 warnings and 6 errors generated.