Page 1 of 1

Visual C++: Including Header Files

Posted: Sat Apr 03, 2010 1:05 pm
by SillyBrick
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.

Re: Visual C++: Including Header Files

Posted: Sat Apr 03, 2010 2:20 pm
by GameDevver4Evr
Try changing

#include <check.h>

to

#include "check.h"

Re: Visual C++: Including Header Files

Posted: Sat Apr 03, 2010 5:31 pm
by SillyBrick
Works, thanks.

Re: Visual C++: Including Header Files

Posted: Sun Apr 04, 2010 10:12 pm
by Ginto8
In case someone curious, I've decided to explain why it works.
When you have the line:

Code: Select all

#include <stdio.h>
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:

Code: Select all

#include "myHeader.h"
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. :)