试着写了一个判断是否持续的函数,能运行但是这几个警告是什么意思
试着写了一个判断是否继续的函数,能运行但是这几个警告是什么意思?
--------------------配置: mingw5 - CUI Debug, 编译器类型: MinGW--------------------
检查文件依赖性...
正在编译 D:\KNNR\test.c...
[Warning] D:\KNNR\test.c:7: warning: initialization makes integer from pointer without a cast
[Warning] D:\KNNR\test.c:11: warning: passing arg 2 of `strcmp' makes pointer from integer without a cast
[Warning] D:\KNNR\test.c:34:2: warning: no newline at end of file
正在连接...
完成构建 test: 0 个错误, 3 个警告
生成 D:\KNNR\test.exe
想搞清楚这几个警告是什么意思
------解决方案--------------------
一切的根源在于:
char* select,a="yes";
这样的定义相当于是char a="yes",所以应该改为:
char* select,*a="yes";
另外有些编译器会要求源代码的最后一行留空,你在最后回车一下添加一个空行即可。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int choice() //判断是否继续的函数
{
char* select,a="yes";
select=(char*)malloc(sizeof(char));
printf("是否继续输入?\n");
gets(select);
if(strcmp(select,a)==1)
{
free(select);
return 0;
}
else
{
free(select);
return 1;
}
}
main()
{
int choice();
int count=1;
while(choice())
{
printf("%d\n",count);
count++;
}
printf("The End!\n");
return 0;
}
--------------------配置: mingw5 - CUI Debug, 编译器类型: MinGW--------------------
检查文件依赖性...
正在编译 D:\KNNR\test.c...
[Warning] D:\KNNR\test.c:7: warning: initialization makes integer from pointer without a cast
[Warning] D:\KNNR\test.c:11: warning: passing arg 2 of `strcmp' makes pointer from integer without a cast
[Warning] D:\KNNR\test.c:34:2: warning: no newline at end of file
正在连接...
完成构建 test: 0 个错误, 3 个警告
生成 D:\KNNR\test.exe
想搞清楚这几个警告是什么意思
------解决方案--------------------
一切的根源在于:
char* select,a="yes";
这样的定义相当于是char a="yes",所以应该改为:
char* select,*a="yes";
另外有些编译器会要求源代码的最后一行留空,你在最后回车一下添加一个空行即可。