简单C程序在Vc++6.0中出错!

来源:百度知道 编辑:UC知道 时间:2024/05/21 12:41:53
我是初学者,有这样一个C程序:
main()
{int a, b, c;
scanf("%d,%d",&a,&b);
c=max(a,b);
printf("max=%d",c);
}
int max(int x,int y)
{
int z;
if(x>y)z=x;
else z=y;
return(z);
}
我刚装了VC++6.0,先是新建project选win32 console application,然后新建文件C++ source file,文件名后面我加了.c 。之后键入上面的程序,编译时有3个警告,运行后,我输入0 1 2,结果却显示max=0.不知道为什么,我想在VC++6.0中只使用C程序,就是我把谭浩强那本书里的c程序键入里面就能运行。我的话可能说不明白,希望高手指点个一二,指点个方向,让我知道该做些什么。感激不尽!

C:\Documents and Settings\F3060239\桌面\MSDN\Test\test.cpp(7) : error C2065: 'max' : undeclared identifier
//加个前向声明

C:\Documents and Settings\F3060239\桌面\MSDN\Test\test.cpp(9) : warning C4508: 'main' : function should return a value; 'void' return type assumed
//给main一个返回值

C:\Documents and Settings\F3060239\桌面\MSDN\Test\test.cpp(11) : error C2373: 'max' : redefinition; different type modifiers
//加个前向声明

#include<stdio.h>

int max(int x,int y);

void main()
{
int a, b, c;
scanf("%d,%d",&a,&b);
c=max(a,b);
printf("max=%d",c);
}
int max(int x,int y)
{
int z;
if(x>y)z=x;
else z=y;
return(z);
}

我只是在你的程序前面加了一行 #include <stdio.h>
编译只有一个WARNING,运行正常~

这样——

scanf("%d %d"