回 帖 发 新 帖 刷新版面

主题:新手求教。忘大师速回

我用TC2.0编个简单的比较两个数大小,   截图如下, 编写的程序没错。可下面的那个错误信息怎么解决?( Undefined symbol '_max' in module NONAME.C)就是这个。    谢谢啦。我才学C语言 





        File   Edit   Run   Compile   Project   Options   Debug   Break/watch
┌──────────────────────────────────── Edit ────────────────────────────────────┐
│      Line 9     Col 1   Insert Indent Tab Fill Unindent * D:NONAME.C         │
│ #include<stdio.h>                                                            │
│ void main()                                                                  │
│ {                                                                            │
│ int max(int x,int y);                                                        │
│ int a,b,c;                                                                   │
│ scanf("%d%d",&a,&b);                                                         │
│ c=max(a,b);                                                                  │
│ printf("max=%d",c);                                                          │
│ }                                                                            │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
╞══════════════════════════════════ Message ═══════════════════════════════════╡
│ Compiling D:\TURBOC2\NONAME.C:                                               │
│ Linking D:\TURBOC2\NONAME.EXE:                                               │
│ Linker Error: Undefined symbol '_max' in module NONAME.C                     │
└──────────────────────────────────────────────────────────────────────────────┘
 F1-Help  F5-Zoom  F6-Switch  F7-Trace  F8-Step  F9-Make  F10-Menu   NUM SCROLL

回复列表 (共5个回复)

沙发

int max(int x,int y); 没有函数体;

 int max(int x,int y)

    return x>y ?x:y;

板凳


谢谢你啦,开始还不懂得,看了书,查了些资料自己搞懂了,呵呵就这么简单的问题我纠结了好几个小时呢。饿,笨蛋呢,,,编程的道路我来了~~~~~~[em9]

3 楼

最后应该这样就行了,呵呵,以后常驻这了,希望大家多多指教。





  File   Edit   Run   Compile   Project   Options   Debug   Break/watch
╒════════════════════════════════════ Edit ════════════════════════════════════╕
│      Line 6     Col 10  Insert Indent Tab Fill Unindent * D:NONAME.C         │
│#include<stdio.h>                                                             │
│int max(int x,int y)                                                          │
│{                                                                             │
│int z;                                                                        │
│if(x>y)z=x;                                                                   │
│else z=y;                                                                     │
│return(z);                                                                    │
│}                                                                             │
│void main()                                                                   │
│{                                                                             │
│int a,b,c;                                                                    │
│scanf("%d,%d",&a,&b);                                                         │
│c=max(a,b);                                                                   │
│printf("max=%d",c);                                                           │
│}                                                                             │
│                                                                              │
│                                                                              │
│                                                                              │
├─────────────────────────────────── Watch ────────────────────────────────────┤
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘
 F1-Help  F5-Zoom  F6-Switch  F7-Trace  F8-Step  F9-Make  F10-Menu   NUM SCROLL

4 楼

上面还可以用另外两种方法表达函数体,



int max(int x,int y)
{
int z;
z=x>y?x:y;
return(z)
}

{
return(x>y?x:y);
}                                                          │

5 楼

你的max()函数只有原型,没有定义啊。在最后
main ()
{
   ...;
}
的后面加上max()的定义就可以了,如下:
int max (int x,int y)
{
   return x>y? x:y;
}

我来回复

您尚未登录,请登录后再回复。点此登录或注册