當我編譯我的代碼,它讓我看到3個警告:警告:格式「%d」需要類型「詮釋」的說法,但參數3的類型爲「詮釋*」
warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘int *’
warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘int *’
warning: format ‘%hhu’ expects argument of type ‘int’, but argument 3 has type ‘unsigned char *’
下面的代碼:
typedef struct
{
int c;
int l;
unsigned char **matrizPixels;
} PGM;
void salvaPGM(PGM *img, char* saida)
{
int i,j;
FILE *arq;
arq = fopen(saida,"w");
fprintf(arq,"P2\n");
fprintf(arq,"%d ", &img->c);
fprintf(arq,"%d ", &img->l);
fprintf(arq,"255\n");
for(i = 0; i++; i < img->l)
{
for (j = 0; j++; j < img->c)
{
fprintf(arq,"%hhu ",&img->matrizPixels[i][j]);
}
fprintf(arq,"\n");
}
fclose (arq);
}
這意味着正是它說。它需要一個'int',但你傳遞給它一個'int *'。 –
除非您嘗試打印地址,否則在printf()的參數前面不需要'&'? –
兩個upvotes。我猜這是再次沒有閱讀編譯器消息日的獎勵! – 2013-08-30 22:24:26