質問編集履歴

1

strcmpの挙動について勘違いがあったので訂正しました。

2020/05/19 08:59

投稿

Reg_py
Reg_py

スコア13

test CHANGED
File without changes
test CHANGED
@@ -1,10 +1,6 @@
1
1
  c言語で、文字列を格納した2次元配列をソートしたいのですが
2
2
 
3
- 全角文字列だとどうもうまくいきません。
3
+ 全角文字列だとどうもうまくいきません。
4
-
5
- その上、関数を呼び出すときに、「int array_size」の部分の値によって
6
-
7
- 出力がまばらになります。
8
4
 
9
5
  おそらくselectionSort関数の書き方が悪いのですが,
10
6
 
@@ -50,7 +46,7 @@
50
46
 
51
47
  for (j = i+1; j < array_size; j++) { // 比較のループ
52
48
 
53
- if (strcmp(numbers[min], numbers[j])) {
49
+ if (strcmp(numbers[min], numbers[j]) > 0 ) {
54
50
 
55
51
  min = j; // 最小値を持つ要素を更新
56
52
 
@@ -100,7 +96,7 @@
100
96
 
101
97
  出力結果
102
98
 
103
- なし。何も出てこない。
99
+ Illegal instruction: 4
104
100
 
105
101
 
106
102
 
@@ -136,7 +132,7 @@
136
132
 
137
133
  出力結果
138
134
 
139
- aab
135
+ Illegal instruction: 4
140
136
 
141
137
 
142
138
 
@@ -146,90 +142,8 @@
146
142
 
147
143
  出力結果
148
144
 
149
- なし。何も出てこない。
145
+ Illegal instruction: 4
150
146
 
151
147
 
152
148
 
153
- ちなみにstrcmpの挙動として
154
-
155
-
156
-
157
- ```C言語
158
-
159
- #include <stdio.h>
160
-
161
- #include <stdlib.h>
162
-
163
- #include <string.h>
164
-
165
-
166
-
167
- #define N 256 // 1単語(形態素)のバイト長
168
-
169
-
170
-
171
- int main(void){
172
-
173
- if(strcmp("あ", "いあああ"))
174
-
175
- printf("True");
176
-
177
-
178
-
179
- else printf("False");
180
-
181
-
182
-
183
- return 0;
184
-
185
- }
186
-
187
-
188
-
189
- ```
190
-
191
- 出力結果 True
192
-
193
-
194
-
195
- ```C言語
196
-
197
- #include <stdio.h>
198
-
199
- #include <stdlib.h>
200
-
201
- #include <string.h>
202
-
203
-
204
-
205
- #define N 256 // 1単語(形態素)のバイト長
206
-
207
-
208
-
209
- int main(void){
210
-
211
- if(strcmp("いああああ", "あ"))
212
-
213
- printf("True");
214
-
215
-
216
-
217
- else printf("False");
218
-
219
-
220
-
221
- return 0;
222
-
223
- }
224
-
225
- ```
226
-
227
- 出力結果 True
228
-
229
-
230
-
231
-
232
-
233
- 以上の二つから、strcmpは全角文字列に対して求める挙動をしないっぽいです。
234
-
235
149
  以上試したことでした。