首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

写一个.h文件,该如何解决

2012-02-09 
写一个.h文件有这个问题[color#FF6600][/color]里的那个程序wordpool.c,如果我想写个wordpool.h是不是这

写一个.h文件
有这个问题[color=#FF6600][/color]里的那个程序wordpool.c,
如果我想写个wordpool.h
是不是这样写?

C/C++ code
#define MAX_WORDS 200#define MAX_SIZE 10typedef struct _wordPool {    int counter;            char word[MAX_SIZE];        } WordPool;int findword(const char *wt);void add(const char *wp);void print() ;



[解决办法]
可以的.
[解决办法]
最好是
C/C++ code
#ifndef    _WORDPOOL_H#define    _WORDPOOL_H#ifdef  __cplusplusextern "C" {#endif#define MAX_WORDS 200#define MAX_SIZE 10typedef struct _wordPool {    int counter;            char word[MAX_SIZE];        } WordPool;int findword(const char *wt);void add(const char *wp);void print() ;#ifdef  __cplusplus}#endif#endif    /*_WORDPOOL_H*/
[解决办法]
楼主的写法是正确的
但最好在最前面加 #program once 避免被多个文件引用的时候 重复定义
[解决办法]
楼主的写法是正确的
但最好在最前面加 #program once 避免被多个文件引用的时候 重复定义


UP

热点排行
Bad Request.