我理解“隐式声明”通常意味着函数在调用之前必须放在程序的顶部,或者我需要声明原型(prototype)。
但是,gets
应该在 stdio.h
文件中(我已经包含了)。
有什么办法可以解决这个问题吗?
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char ch, file_name[25];
FILE *fp;
printf("Enter the name of file you wish to see\n");
gets(file_name);
fp = fopen(file_name,"r"); // read mode
if( fp == NULL )
{
perror("Error while opening the file.\n");
exit(EXIT_FAILURE);
}
}
最佳答案
你是对的,如果你包含正确的标题,你不应该得到隐式声明警告。
然而,函数gets()
已从 C11 标准中删除。这意味着不再有 gets()
的原型(prototype)在 <stdio.h>
. gets()
曾经在<stdio.h>
.
删除gets()
的原因众所周知:它无法防止缓冲区溢出。因此,你不应该使用 gets()
并使用 fgets()
相反,并处理尾随的换行符(如果有的话)。
关于c - 'gets' 的隐式声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34031514/