Hey, guys.
I'm trying to make a DOS rpg, and I want to split my code into header files (like some functions and variables) anyways,
I have the files in my project.... but it can't find them.
So, I have two files.
One, "Main" in my "Source Files" folder.
And another, "check.h" in my "Header Files" folder.
Here is the code in my Main file:
#include <stdio.h>
#include <check.h>
int ehp;
float exp;
char name[12];
int main()
{
printf("Hello, please enter your name \n ");
scanf(name);
printf("%s", name);
printf("\n");
getchar();
return 0;
}
and here is the code in my check.h file:
int hp;
int hcheck()
{
if(hp == 0 < 1)
printf("\n \a Game Over, you died");
return 0;
}
the error I get: fatal error C1083: Cannot open include file: 'check.h': No such file or directory
How do I get it to find the other file?
Thanks.
Visual C++: Including Header Files
Moderator: Coders of Rage
-
- Chaos Rift Newbie
- Posts: 5
- Joined: Thu Apr 01, 2010 5:28 pm
-
- Chaos Rift Newbie
- Posts: 33
- Joined: Mon Mar 08, 2010 9:34 pm
Re: Visual C++: Including Header Files
Try changing
#include <check.h>
to
#include "check.h"
#include <check.h>
to
#include "check.h"
-
- Chaos Rift Newbie
- Posts: 5
- Joined: Thu Apr 01, 2010 5:28 pm
Re: Visual C++: Including Header Files
Works, thanks.
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Visual C++: Including Header Files
In case someone curious, I've decided to explain why it works.
When you have the line:
the brackets tell the compiler to look in it's own directory of header files. This directory can include the standard library's headers, the headers of other libraries such as OpenGL, ncurses, Qt, SDL, etc.
On the other hand, in this line of code:
the quotes tell it that it is a header file local to your project. That means that, even if there is a standard header by the name myHeader.h, the first place the compiler will look is the directory of your source file.
Now, this last bit I'm not totally certain about, but it seems to be correct. If you include something with quotes, and there is no available file in the current source directory, it will look in other areas (mainly those specified by certain compiler flags, such as -I for GCC). That's why including, say, the SDL header files with quotes will still retrieve them even though they're in a very different location on your hard drive.
When you have the line:
Code: Select all
#include <stdio.h>
On the other hand, in this line of code:
Code: Select all
#include "myHeader.h"
Now, this last bit I'm not totally certain about, but it seems to be correct. If you include something with quotes, and there is no available file in the current source directory, it will look in other areas (mainly those specified by certain compiler flags, such as -I for GCC). That's why including, say, the SDL header files with quotes will still retrieve them even though they're in a very different location on your hard drive.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.