C语言头文件正确写法
一般写法
例如这样有一个file.h
头文件,一般写法如下
//file.h
//条件编译
#ifndef _FILE_H_ //如果没有引入头文件file.h
#define _FILE_H_ //那就引入头文件file.h
//结构体和函数声明....
//1 根据跟文件路径和模式获取文件指针
FILE* getFILE(char* filePath,char* mode);
//2 使用临时文件替换原文件
void updateOldFileByNew(char*oldFileName,char*newFileName);
#endif
自动生成
当然,手动写还是有点麻烦,所以我写了点js代码来自动生成:
<html>
<head>
<meta charset="utf-8">
<title>生成c语言头文件声明</title>
<script> function daxie() { var input = document.getElementById("output"); input.value = input.value.toUpperCase(); //变成大写 } function createCHeadFile() { //User.h // #ifndef _USER_H_ //如果没有引入头文件User.h // #define _USER_H_ //那就引入头文件User.h // #endif var input = document.getElementById("output"); var oldValue = input.value; //保存原来的值 var daxie = input.value.toUpperCase(); //变成大写 input.value = "//" + oldValue + ".h\n" + "#ifndef _" + daxie + "_H_ //如果没有引入头文件" + oldValue + ".h\n" + " #define _" + daxie + "_H_ //那就引入头文件" + oldValue + ".h\n" + "#endif"; } </script>
</head>
<body>
<textarea rows="10" cols="100" id="output"></textarea><br>
<!-- <input type="button" name="button1" id="button1" value="变成大写" οnclick="daxie()" /> -->
<input type="button" name="butto2" id="button2" value="生成c语言头文件声明" onclick="createCHeadFile()" />
</body>
</html>
如何使用
复制上面的代码,保存成.html
文件,然后用浏览器打开这个html
文件,在文本框中输入不带后缀的头文件名,例如我要生成file.h
的头文件代码,则输入文件名file
,然后点击生成c语言头文件声明
:
运行结果会出现在这个文本框中:
运行结果
//file.h
#ifndef _FILE_H_ //如果没有引入头文件file.h
#define _FILE_H_ //那就引入头文件file.h
#endif
然后把代码粘贴到头文件file.h
中即可。
参考链接
https://blog.csdn.net/Com_ma/article/details/78546807
https://blog.csdn.net/K346K346/article/details/48877773
https://blog.csdn.net/wr132/article/details/65635003
https://blog.csdn.net/abc_12366/article/details/79155540
https://blog.csdn.net/wr132/article/details/65635003
https://blog.csdn.net/wandermen/article/details/9254919
https://blog.csdn.net/xhbxhbsq/article/details/78955216
还没有评论,来说两句吧...