前提
#c
#C99
すごい初歩的な質問なんですけど、整数型の書式指定は%dで合ってますよね?データ型が合わない的なエラーが出たんですが、よくわからないです。int *型とは何でしょうか。
発生している問題・エラーメッセージ
3.7.c:9:25: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=] 9 | printf("x>"); scanf("%d", x); | ~^ ~ | | | | | int | int * 3.7.c:10:25: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=] 10 | printf("y>"); scanf("%d", y); | ~^ ~ | | | | | int | int * 3.7.c:11:30: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=] 11 | printf("割られる数 = %d, 商 = %d, 余り = %d, x, y, amari(x, y)"); | ~^ | | | int 3.7.c:11:40: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=] 11 | printf("割られる数 = %d, 商 = %d, 余り = %d, x, y, amari(x, y)"); | ~^ | | | int 3.7.c:11:53: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=] 11 | printf("割られる数 = %d, 商 = %d, 余り = %d, x, y, amari(x, y)"); | ~^ | | |
該当のソースコード
一応こんな感じのコードを書きました。
#include<stdio.h> int amari(int x, int y){ int z; z = x % y; return z; } int main(){ int x, y; printf("x>"); scanf("%d", x); printf("y>"); scanf("%d", y); printf("割られる数 = %d, 商 = %d, 余り = %d, x, y, amari(x, y)"); }
printf と scanf では、フォーマットの指定は同じでも対応する変数の型は大抵違います。
そして、割られる数の printf は別の間違いです。

回答1件
あなたの回答
tips
プレビュー