###前提・実現したいこと
C言語でキーボードから入力した文字(character)を表示した後、その文字のASCIIコードを表示するコードを書いています。以下のエラーがコンパイル時に表示され、どのように改善すればいいかわからず、困っています。
###発生している問題・エラーメッセージ
C
1ex2_3.c: In function ‘main’: 2ex2_3.c:6:10: warning: format ‘%c’ expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=] 3 printf("input data=%c\n", &a); 4 ^ 5ex2_3.c:7:9: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘char *’ [-Wformat=] 6 scanf("%d", &a);
###該当のソースコード
C
1#include <stdio.h> 2int main(){ 3 char a; 4 printf("input a character="); 5 scanf("%c", &a); 6 printf("input data=%c\n", &a); 7 scanf("%d", &a); 8 printf("input data ASCII code=%d\n",*(&a)); 9 return 0; 10} 11
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/11/11 01:36
退会済みユーザー
2017/11/11 02:17