我的程序出现警告,我不知道如何解决。首先,我收到警告 passing argument 3 of "fgets"from incompatible pointer type
。这是我的程序:
bool get_name(char name[],char buff[])
{
if(isalpha(buff))
{
fgets(name,sizeof(MAXNAME),buff);
return name;
}
else
{
return false;
}
}
最佳答案
回答题目中的问题
来自man page对于 fgets()
,签名是
char *fgets(char *s, int size, FILE *stream)
其中,第三个参数是 FILE *
类型。您不能在那里传递 char *
。
此外,引用 C11
,第 7.21.7.2 章
The
fgets
function reads at most one less than the number of characters specified byn
from the stream pointed to bystream
into the array pointed to bys
. [...]
因此,它必须是流,而不是char
数组或其他形式的文件名。
注意:
正如 Mr. Jonathan Leffler 正确提到的那样在评论中,从问题描述来看,您根本不需要在代码中使用 fgets()
。请先将问题陈述分解成笔和纸的算法以消除混淆,然后再回来重新编写代码。
关于c - 从不兼容的指针类型传递参数 3 of “fgets ”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39337809/