加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

codeblocks:如何调用其他项目中的头文件

(2018-04-25 17:12:20)
标签:

it

1. 复制所需头文件的绝对路径;
2. 开启要调用该头文件的主程序;
3. 将复制好的绝对路径插入引用该头文件的命令行 #include“”中的双引号即可。
示范程序:其中主程序引自台大资源系PangFeng Liu的C语言教学视频

//以下三个标准头文件的命令,因新浪博客存在bug,误认某特殊符号为广告而无法完整上传,请原谅。
#include 
#include
#include

//以下两行是调用其他项目中两个头文件 Student.h 和 printStudent.h 的示范:

#include"I:\C 语言\firstProgram\fwrite_student-array\Student.h"
#include"I:\C 语言\firstProgram\fwrite_student-array\printStudent.h"

//下面是主程序

int main()
{
    FILE *fp;
    Student a[3] = {{"John Smith",
        12345, "1234567",
        {3.0, 3.0, 3.0, 3.0},
        2000, 1, 1},
        {"Mary Smith", 67890, "7654321",
        {4.0, 4.0, 4.0, 4.0}, 2000, 2, 2},
        {"Smith Smith", 34567, "4321765",
        {2.0, 2.0, 2.0, 2.0}, 2000, 3, 3}};
    Student b;
    int i;
    int c;
    int count;

    fp = fopen("file", "wb");
    assert(fp !=NULL);
    fwrite(a, sizeof(Student), 3, fp);
    fclose(fp);

    fp = fopen("file", "rb");
    assert(fp != NULL);
    fseek(fp, 1 * sizeof(Student), SEEK_SET);
    fread(&b, sizeof(Student), 1, fp);
    print_student(&b);
    fseek(fp, -2 * sizeof(Student), SEEK_CUR);
    fread(&b, sizeof(Student), 1, fp);
    print_student(&b);
    fseek(fp, -1 * sizeof(Student), SEEK_END);
    fread(&b, sizeof(Student), 1, fp);
    print_student(&b);
    fclose(fp);
    return 0;
}


0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有