c语言中要封装一个函数( 比如什么printf之类的),肯定得用.c和.h文件,函数声明在.h文件中.函数实现在c文

c语言中要封装一个函数( 比如什么printf之类的),肯定得用.c和.h文件,函数声明在.h文件中.函数实现在c文件中,怎么把他们静态编译成lib文件供其他程序调用??具体过程是怎样的??在给小菜提供一个.c和.h文件的代码例子啊!谢谢!

//mvector.h -- 声明
#ifndef MVECTOR_H_
#define MVECTOR_H_  
typedef struct _mvect
{
int x;
int y;
}vect;
void getvect(vect* v);//声明
void showvect(vect v);//声明
#endif

//mvector.c -- 实现
#include "mvector.h"
#include <stdio.h> 
void getvect(vect* v)
{
scanf("%d,%d",&(v->x),&(v->y));  
 }  
void showvect(vect v)
{
printf("%d,%d",v.x,v.y);  
 }

//main.c -- 使用
#include "mvector.h"
#include <stdio.h>
int main()
{
vect a;
getvect(&a);
showvect(a);
}

注意mvector.h必须位于当前文件夹下,且必须把mvector.c和main.c放在一个工程里编译。

输入:2,3

输出:2,3

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-08-27
你写一个。h的文件,然后然后再写.c文件的时候就可以调用了通过#
相似回答