作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我的变量和返回值匹配时,我不知道为什么会收到此警告。我已经粘贴在变量下方,将该变量赋值给函数和函数本身(返回值和所有)
char * menuMsg; /* used to print menu options */
menuMsg = printMenu();
char * printMenu()
{
static char message[250] = "Select an option from below:\n";
strcat(message, "(1) List all files on server\n");
strcat(message, "(2) Retrieve file from server\n");
strcat(message, "(3) Retrieve all files from server\n");
strcat(message, "Enter your selection: ");
return message;
}
关于我为什么会收到此错误的任何线索?对我来说,它们都符合类型声明的条款。
最佳答案
发生这种情况是因为您在函数声明之前调用它。假定未声明的函数返回 int
,这解释了错误。
将 printMenu()
定义移动到执行调用的函数之前,或添加一个原型(prototype):
char * printMenu(void);
并确保添加 void
,()
对于不接受任何参数的函数是错误的。
此外,您的代码已损坏,因为每次调用 printMenu()
时,它都会调用 strcat()
四次,导致菜单文本越来越大,最终导致缓冲区溢出。
关于C-警告 : assignment makes pointer from integer without a cast,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26425450/
我是一名优秀的程序员,十分优秀!