发布网友
共4个回答
热心网友
test1.h中:
int i;
test2.c中:
#include <stdio.h>
#include "test1.h"
extern int i;
int main()
{
i = 3;
printf("%d",i);
}
受文件作用域的*,全局变量或函数在其他文件中使用时必须加上关键字extern。extern的作用是指出该变量i在其他文件中声明或定义。而且你应该将要被包含的文件统统设置为.h的头文件格式,记住要编出好的程序的要素之一就是包含中没有.c或.cpp文件形式的存在。
热心网友
test1.c没放include目录里?
看这篇对你有帮助不.
http://www.1to2.us/c-include-a55172.htm
当c看就成.
热心网友
你不妨把text1.c改成text1.h后,把text1.h放在你安装vc++目录下的include下,然后把text2.c下的代码#include<test1.c> 也改变成#include<test1.h>,然后编译运行试下.
热心网友
你把#include<test1.c> 改成#include<test1.h> 试试……