c言語初心者です。
文字列を取り込んで大文字と小文字を変えるプログラムをc言語で書いているのですが、
コンパイルすると下に記述したような警告が出ます。
正直、よくわからなくて混乱しています。
何がダメなんでしょうか。
どなたか教えていただけると幸いです。
c
1#include<stdio.h> 2#include<string.h> 3 4char abc[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOQRSTUVWXYZ"; 5 6char *change(char *a){ 7 int i,j; 8 for(i=0;i<26;i++){ 9 if(strcmp(a,abc[i])){ 10 return abc[i+26]; 11 } 12 } 13for(i=26;i<52;i++){ 14 if(strcmp(a,abc[i])){ 15 return abc[i-26]; 16 } 17 } 18} 19 20int main(){ 21int i,j,n; 22char a; 23while(scanf("%c",&a)!=EOF){ 24printf("%c",change(a)); 25} 26 return 0; 27}
terminal
1gcc -o huku8-1 huku8-1.c 2huku8-1.c: In function ‘change’: 3huku8-1.c:9:20: warning: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast [-Wint-conversion] 4 9 | if(strcmp(a,abc[i])){ 5 | ~~~^~~ 6 | | 7 | char 8In file included from huku8-1.c:2: 9/usr/include/string.h:137:50: note: expected ‘const char *’ but argument is of type ‘char’ 10 137 | extern int strcmp (const char *__s1, const char *__s2) 11 | ~~~~~~~~~~~~^~~~ 12huku8-1.c:10:19: warning: returning ‘char’ from a function with return type ‘char *’ makes pointer from integer without a cast [-Wint-conversion] 13 10 | return abc[i+26]; 14 | ~~~^~~~~~ 15huku8-1.c:14:20: warning: passing argument 2 of ‘strcmp’ makes pointer from integer without a cast [-Wint-conversion] 16 14 | if(strcmp(a,abc[i])){ 17 | ~~~^~~ 18 | | 19 | char 20In file included from huku8-1.c:2: 21/usr/include/string.h:137:50: note: expected ‘const char *’ but argument is of type ‘char’ 22 137 | extern int strcmp (const char *__s1, const char *__s2) 23 | ~~~~~~~~~~~~^~~~ 24huku8-1.c:15:19: warning: returning ‘char’ from a function with return type ‘char *’ makes pointer from integer without a cast [-Wint-conversion] 25 15 | return abc[i-26]; 26 | ~~~^~~~~~ 27huku8-1.c: In function ‘main’: 28huku8-1.c:24:20: warning: passing argument 1 of ‘change’ makes pointer from integer without a cast [-Wint-conversion] 29 24 | printf("%c",change(a)); 30 | ^ 31 | | 32 | char 33huku8-1.c:6:20: note: expected ‘char *’ but argument is of type ‘char’ 34 6 | char *change(char *a){ 35 | ~~~~~~^ 36huku8-1.c:24:10: warning: format ‘%c’ expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=] 37 24 | printf("%c",change(a)); 38 | ~^ ~~~~~~~~~ 39 | | | 40 | | char * 41 | int 42 | %s
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。