头文件编写问题

来源:百度知道 编辑:UC知道 时间:2024/05/25 17:09:32
我想请问下,就是如何编写头文件,我找了一个例子,但是报错提示,说是没有定义函数max.
----------------------------------main.c------------------------
#include <stdio.h>
#include <stdlib.h>
#include "defin.h"

int main(void)
{
int x, y, sum;
puts("Enter x and y:");
scanf("%d %d", &x, &y);
sum = max(x, y);
printf("The max number is: %d", sum);
system("pause");
return 0;
}
--------------------------------defin.h------------------------
int max(int a, int b);
--------------------------------max.c--------------------------
#include "defin.h"

int max(int a, int b)
{
return (a > b ? a : b);
}

应在MAIN.C中先声明
int max(int a, int b);

#include <stdio.h>
#include <stdlib.h>
#include "defin.h"
#include "defin.h"
int main(void)
{
int max(int a, int b);
int x, y, sum;
puts("Enter x and y:");
scanf("%d %d", &x, &y);
sum = max(x, y);
printf("The max number is: %d", sum);
system("pause");
return 0;
}
int max(int a, int b)
{
return (a > b ? a : b);
}

怀疑是你的编译参数有问题..
这样可以过的

在main.c中声明一下应该就可以了