【发布时间】:2015-05-06 16:40:24
【问题描述】:
我在尝试编写只允许数字字符串的程序时收到以下警告:
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);
}
【问题讨论】:
-
标题具有误导性;警告与
isdigit无关。 -
从
sscanf(lne, "%s", &check);中取出&此外,在代码行之间留一些空格,遵循样式指南等。您的int main应该是int main(void)。