C语言多文件的使用
1、定义头文件head.h
头文件存放内容:
- 其他需要使用的头文件
- 函数或全局变量的声明
- 结构体的声明
- 宏的定义
//使用ifndef使得该文件被多次引用时,会被宏隔绝
#ifndef __HEADD_H__
#define __HEADD_H__
#include<stdio.h>
extern int m;
extern int n;
extern int find_max();
#define STR "you will become a jocker"
#endif
2、定义功能文件calc.c
#include "head.h"
int m;
int n;
int find_max(int m,int n){
return m>n?m:n;
}
3、定义主函数文件
#include "head.h"
int main(){
printf("please enter two num:\n");
scanf("%d,%d",&m,&n);
int result=find_max(m,n);
printf("%d\n",result);
printf("%s\n",STR);
return 0;
}
编译
编译:gcc calc.c main.c./a.out