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

回答編集履歴

3

追記

2019/04/23 09:47

投稿

cateye
cateye

スコア6851

answer CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
 
4
4
  それは文字列の名前だけ([]が付かない)の比較じゃないでしょうか?
5
+ __※わたしも探してみましたが文字列を途中からコピーしたり比較したりする例は見つかりませんでした。__
5
6
 
6
7
  strcmp()やstrcpy()は文字列(終端が'\0')を対象とする関数です。
7
8
  文字の比較ではありません。したがって

2

追記

2019/04/23 09:47

投稿

cateye
cateye

スコア6851

answer CHANGED
@@ -6,4 +6,52 @@
6
6
  strcmp()やstrcpy()は文字列(終端が'\0')を対象とする関数です。
7
7
  文字の比較ではありません。したがって
8
8
  strcmp(newWord[i], WORDlist[i]) は、は文字をアドレスとして渡していることになります。
9
- エラーにならなければ、何が起こってもしょうがない状況です。
9
+ エラーにならなければ、何が起こってもしょうがない状況です。
10
+ 「追記」
11
+ そのままコンパイルすると以下のワーニングが出ます。
12
+ ・・・説明の出来ないエラーやワーニングは潰しましょう。
13
+ 参考:[エラーメッセージの読み方と対処, 検索や質問の原則](https://qiita.com/cannorin/items/eb062aae88bfe2ad6fe5)
14
+ ```text
15
+ usr ~/Project/test % cc t4.c
16
+ t4.c:18:8: warning: implicit conversion loses integer precision: 'int' to 'char'
17
+ [-Wimplicit-int-conversion]
18
+ ch=fgetc(fp);//ファイルから一文字読み取る
19
+ ~^~~~~~~~~
20
+ t4.c:20:10: warning: implicitly declaring library function 'strcmp' with type 'int
21
+ (const char *, const char *)' [-Wimplicit-function-declaration]
22
+ if(strcmp(newWord[i], WORDlist[i]) == 0)
23
+ ^
24
+ t4.c:20:10: note: include the header <string.h> or explicitly provide a declaration for 'strcmp'
25
+ t4.c:20:17: warning: incompatible integer to pointer conversion passing 'char' to parameter of
26
+ type 'const char *'; take the address with & [-Wint-conversion]
27
+ if(strcmp(newWord[i], WORDlist[i]) == 0)
28
+ ^~~~~~~~~~
29
+ &
30
+ t4.c:20:29: warning: incompatible integer to pointer conversion passing 'char' to parameter of
31
+ type 'const char *'; take the address with & [-Wint-conversion]
32
+ if(strcmp(newWord[i], WORDlist[i]) == 0)
33
+ ^~~~~~~~~~~
34
+ &
35
+ t4.c:28:7: warning: implicitly declaring library function 'strcpy' with type
36
+ 'char *(char *, const char *)' [-Wimplicit-function-declaration]
37
+ strcpy(WORDlist[i], newWord[i]);//WORDlistに登録 文字列なので =で代入できない
38
+ ^
39
+ t4.c:28:7: note: include the header <string.h> or explicitly provide a declaration for 'strcpy'
40
+ t4.c:28:14: warning: incompatible integer to pointer conversion passing 'char' to parameter of
41
+ type 'char *'; take the address with & [-Wint-conversion]
42
+ strcpy(WORDlist[i], newWord[i]);//WORDlistに登録 文字列なので =で代入できない
43
+ ^~~~~~~~~~~
44
+ &
45
+ t4.c:28:27: warning: incompatible integer to pointer conversion passing 'char' to parameter of
46
+ type 'const char *'; take the address with & [-Wint-conversion]
47
+ strcpy(WORDlist[i], newWord[i]);//WORDlistに登録 文字列なので =で代入できない
48
+ ^~~~~~~~~~
49
+ &
50
+ t4.c:32:15: warning: variable 'ch' used in loop condition not modified in loop body
51
+ [-Wfor-loop-analysis]
52
+ for(i=0; (( ch!='\0' ) && ( ch!=EOF )); i++){ //文字列の最後に含まれている\0
53
+ ^~ ~~
54
+ 8 warnings generated.
55
+ usr ~/Project/test %
56
+
57
+ ```

1

誤記修正

2019/04/23 09:01

投稿

cateye
cateye

スコア6851

answer CHANGED
@@ -6,4 +6,4 @@
6
6
  strcmp()やstrcpy()は文字列(終端が'\0')を対象とする関数です。
7
7
  文字の比較ではありません。したがって
8
8
  strcmp(newWord[i], WORDlist[i]) は、は文字をアドレスとして渡していることになります。
9
- ニングにならなければ、何が起こってもしょうがない状況です。
9
+ エラーにならなければ、何が起こってもしょうがない状況です。