[英]Warning with sscanf format
嘗試編寫僅允許數字字符串的程序時,出現以下警告:
warning: format '%s' expects argument of type char *', but argument 3 has type 'char (*)[100]'
為什么會收到此警告,它的含義/后果是什么? 運行代碼沒有任何問題。
該程序:
char check[100];
char line[100];
int i;
int true = 0;
int main
{
fgets(line, sizeof(line), stdin);
sscanf(line, "%s" , &check);
for(i=0; i<3; i++)
{
if(isdigit(check[i]) == 0)
{
true++;
}
else
continue;
}
if(true>0)
printf("Not a number.\n");
else
printf("Is a number.\n");
return(0);
}
編譯器在下一行中抱怨使用&check
。
sscanf(line, "%s" , &check);
預期的參數只是check
。
sscanf(line, "%s" , check);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.