implicit declaration of function

tyg1982 2005-10-10 06:32:38
dev c++中编译程序
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int a,b,c;
scanf("%d,d%",&a,&b);
c=max(a,b);
printf("max = %d",c);
return 0;
}
int max(int x,int y) //错误:implicit declaration of function
~~~~~~~~~~~~~~~~~~~~~
{int z;
if(x>y) z=x;
else z=y;
return(z);
}
...全文
1164 17 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
tyg1982 2005-10-11
  • 打赏
  • 举报
回复
呵呵,太粗心了,谢谢大家
tyg1982 2005-10-11
  • 打赏
  • 举报
回复
恩,好的,程序通过了,谢谢各位,结铁
xlsue 2005-10-10
  • 打赏
  • 举报
回复
呵呵,没注意到: scanf函数中的那个:)
wanguodu 2005-10-10
  • 打赏
  • 举报
回复
楼主的程序有两处错误:
1、scanf("%d,d%",&a,&b);应为scanf("%d,%d",&a,&b);
2、函数max()没有前向声明。
编译通过,运行也正确的程序:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int max(int x,int y);

int main(int argc, char *argv[])
{
int a,b,c;

scanf("%d,%d",&a,&b);
c=max(a,b);
printf("max = %d",c);
return 0;
}

int max(int x,int y) //错误:implicit declaration of function
{
int z;
if(x>y) z=x;
else z=y;
return(z);
}

输入:
100,200
输出:
200
xlsue 2005-10-10
  • 打赏
  • 举报
回复
那不知道了,没用Dec-c++来写C过。
tyg1982 2005-10-10
  • 打赏
  • 举报
回复
呵呵,没用。
c语言中函数的位置没那么重要吧???
一样的结果,编译通过,答案不正确
xlsue 2005-10-10
  • 打赏
  • 举报
回复
我记得C89规定函数原型必须出现在调用之前。有两种修改形式:
//1.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int max(int , int);

int main(int argc, char *argv[])
{
int a,b,c;
scanf("%d,d%",&a,&b);
c=max(a,b);
printf("max = %d",c);
return 0;
}
int max(int x,int y) //错误:implicit declaration of function
{
int z;

if(x>y)
z=x;
else
z=y;

return z;
}

//2.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int max(int x,int y) //错误:implicit declaration of function
{
int z;

if(x>y)
z=x;
else
z=y;

return z;
}


int main(int argc, char *argv[])
{
int a,b,c;
scanf("%d,d%",&a,&b);
c=max(a,b);
printf("max = %d",c);
return 0;
}
tyg1982 2005-10-10
  • 打赏
  • 举报
回复
为什么不可以啊?这些代码本来就是在tc来调试的啊,只不过我现在在devc++下编译而已。环境不一样,编译就不一定通过了,你帮我试一下啊
xlsue 2005-10-10
  • 打赏
  • 举报
回复
不是吧?TC2。0可以?我好像记得我以前用的时候是不可以的。
tyg1982 2005-10-10
  • 打赏
  • 举报
回复
不过有下面的问题:
~~~~~~~~~~~~~~~~~~~~~~~
输入值
a=4,b=5
max=65536
~~~~~~
明显的最后的值是错误的,而且输入任何数都是这个值????
tyg1982 2005-10-10
  • 打赏
  • 举报
回复
确实,删掉前面的int编译通过
megaboy 2005-10-10
  • 打赏
  • 举报
回复
max没有声明,C89隐含声明max为extern int max(),而你的max定义为int max(int,int),形参部分与声明不符,所以会报error。
tyg1982 2005-10-10
  • 打赏
  • 举报
回复
呵呵, vc不标准,所以我偶不用的。
格兰特杨 2005-10-10
  • 打赏
  • 举报
回复
大部分都不行啊,老兄。vc也一样的
tyg1982 2005-10-10
  • 打赏
  • 举报
回复
知道,在tc2是可以的,不过在devc++下通不过
K 2005-10-10
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int max(int,int);
int main(int argc, char *argv[])
{
int a,b,c;
scanf("%d,d%",&a,&b);
c=max(a,b);
printf("max = %d",c);
return 0;
}
int max(int x,int y) //错误:implicit declaration of function
~~~~~~~~~~~~~~~~~~~~~
{int z;
if(x>y) z=x;
else z=y;
return(z);
}

MoriyaLB 2005-10-10
  • 打赏
  • 举报
回复
在main函数前面加上
int max(int x ,int y);
这叫作函数的向前声明,否则main不知道max是什么东西

15,447

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧