将函数写在一个头文件中。
首先是头文件,也就是被引用的文件。
/* single_methods.h */
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
int str2int(char c)
{
switch (c)
{
case 'A':
return 0;
case 'C':
return 1;
case 'G':
return 2;
case 'T':
return 3;
}
return 4;
}
接下来,编写程序来调用该头文件中的方法。
/* helloWorld.c */
#include <limits.h>
#include <stdio.h>
#include "./new_Code_trail/single_methods.h"
int main()
{
int result_=str2int('A');
printf("result_= %d\n",result_);
return 0;
}
运行结果
运行成功
更多推荐
C语言跨文件调用函数
发布评论