visual 2008: can't find header

A

Adam Chapman

Hi,

Im using Visual C++ 2008, I made a header file (well, copied the
header "cat.h" from http://en.wikipedia.org/wiki/Opaque_pointer)

The only mention of cat.h I have in my script containing main() is the
line:
#include <cat.h>

I've saved the header file within the same project as the script
containing main. When compiling, i get the error message:

fatal error C1083: Cannot open include file: 'cat.h': No such file or
directory

Im incredibly new to C, and my guess is that I need to tell the
compiler to look in my project directory for headers.

Does anyone know how to do this or can advise me otherwise?

Thanks,
Adam
 
A

Adam Chapman

Hi,

Im using Visual C++ 2008, I made a header file (well, copied the
header "cat.h" fromhttp://en.wikipedia.org/wiki/Opaque_pointer)

The only mention of cat.h I have in my script containing main() is the
line:
#include <cat.h>

I've saved the header file within the same project as the script
containing main. When compiling, i get the error message:

fatal error C1083: Cannot open include file: 'cat.h': No such file or
directory

Im incredibly new to C, and my guess is that I need to tell the
compiler to look in my project directory for headers.

Does anyone know how to do this or can advise me otherwise?

Thanks,
Adam

Aha! Should have used "cat.h" rather than <cat.h>. Is this a standard
syntax for user-created headers?
 
F

Flash Gordon

Adam Chapman wrote, On 14/10/08 20:59:
Hi,

Im using Visual C++ 2008, I made a header file (well, copied the
header "cat.h" from http://en.wikipedia.org/wiki/Opaque_pointer)

The only mention of cat.h I have in my script containing main() is the
line:
#include <cat.h>

You should ony use angle brackets for include files provided by your
system, you should use double-quotes for headers you provide. I.e. try

#include "cat.h"
I've saved the header file within the same project as the script
containing main. When compiling, i get the error message:

fatal error C1083: Cannot open include file: 'cat.h': No such file or
directory

Im incredibly new to C, and my guess is that I need to tell the
compiler to look in my project directory for headers.

Does anyone know how to do this or can advise me otherwise?

For help on how to use Visual Studio you should use one of the Windows
programming groups. However my guess is that with the change above you
will get rid of the error.
 
F

Flash Gordon

Adam Chapman wrote, On 14/10/08 21:02:

Aha! Should have used "cat.h" rather than <cat.h>. Is this a standard
syntax for user-created headers?

Yes. Quotes for user headers angle brackets for system provided headers.
 
A

Adam Chapman

Thanks guys.

Looking at the C example at http://en.wikipedia.org/wiki/Opaque_pointer
, Could you show me how to use the create_Cat function from my main
script? I'ts difficult to tell what inputs I need, most probably
because Im dumb. I think it would be something like this:

#include "cat.h"

main(void){
int smile;
smile = 1;
..... create_Cat(int smile);
}

But am not sure what to put in the place of the .... .
 
A

Adam Chapman

what does create_Cat return? Can you show us the contents of cat.h ?

My understanding is that create_Cat creates a new variable with a data
type defied in cat.h . I want to know how to call it so I can make my
own. I plan to make a structure type which holds 2D matrix values and
dimensions.
 
L

Lew Pitcher

Thanks guys.

Looking at the C example at http://en.wikipedia.org/wiki/Opaque_pointer
, Could you show me how to use the create_Cat function from my main
script? I'ts difficult to tell what inputs I need, most probably
because Im dumb. I think it would be something like this:

#include "cat.h"

main(void){
int smile;
smile = 1;
.... create_Cat(int smile);
}

But am not sure what to put in the place of the .... .

OK. You /really/ need help learning C, don't you. Are you certain that your
name isn't "Bill Cunningham"?

1) You will need to compile the second set of logic shown on that webpage,
either as part of the source code file (officially, the "translation unit")
that your main() function is in, or as a separate source code file. If you
choose to make it a separate source code file, you will have to instruct
your linker to use the compiled functions when it links your main()
function.

2) The "cat.h" example file given on the webpage is incomplete. It provides
typedef struct cat_t *cat_handle;
which makes the typename cat_handle to be an alias to the type
"pointer to struct cat_t"
but it /does not/ define the
struct cat_t
at all. However, you can find the structure definition for cat_t in the
second example code. My recommendation would be to remove it from the
second example, and move it to the cat.h header.

3) You actually had a good start in the lines above. Assuming that you move
the cat_t structure definition to cat.h, you will need something like...

#include "cat.h"

int main(void)
{
cat_handle MyCat;

MyCat = createCat(1);

/* what ever other logic you want to use goes here */

return 0;
}


HTH
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
L

Lew Pitcher

Thanks guys.

Looking at the C example at http://en.wikipedia.org/wiki/Opaque_pointer
[snip]
2) The "cat.h" example file given on the webpage is incomplete. It
provides
typedef struct cat_t *cat_handle;
which makes the typename cat_handle to be an alias to the type
"pointer to struct cat_t"
but it /does not/ define the
struct cat_t
at all. However, you can find the structure definition for cat_t in the
second example code. My recommendation would be to remove it from the
second example, and move it to the cat.h header.

Oops. I screwed that one up, didn't I?

The whole point of data hiding is that you don't have to do what I told you
to do. If I were on SNL in the 80's, I'd say "Never mind" (others will get
the reference), but I'm not, so I'll just apologize instead.

With the code supplied, all you have to do is....

#include "cat.h"

int main(void)
{
cat_handle MyCat;

MyCat = create_Cat(1);
/* et cetera */

return 0;
}



[snip]

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
H

Harald van Dijk

2) The "cat.h" example file given on the webpage is incomplete. It
provides
typedef struct cat_t *cat_handle;
which makes the typename cat_handle to be an alias to the type
"pointer to struct cat_t"
but it /does not/ define the
struct cat_t
at all.

The idea is to not expose the definition of struct cat_t, because the
calling code doesn't need it.
However, you can find the structure definition for cat_t in the
second example code. My recommendation would be to remove it from the
second example, and move it to the cat.h header.

My recommendation would be to leave it in its current place.
 
C

CBFalconer

Adam said:
Im using Visual C++ 2008, I made a header file (well, copied the
header "cat.h" from http://en.wikipedia.org/wiki/Opaque_pointer)

The only mention of cat.h I have in my script containing main()
is the line:
#include <cat.h>

That line searches only the area that holds system headers. cat.h
is not a system header, it is something of yours, so use:

#include "cat.h"

Note the quote markers.
 
R

Richard Nixon

That line searches only the area that holds system headers. cat.h
is not a system header, it is something of yours, so use:

#include "cat.h"

Note the quote markers.

Gosh, CB, your politeness reminds me of your better nature.

For the OP, will you go out and find a good newsgroup where this is
topical? (A good one)

Please repost when you succeed.
 
C

CBFalconer

Richard said:
Gosh, CB, your politeness reminds me of your better nature.

For the OP, will you go out and find a good newsgroup where this is
topical? (A good one)

Well done. You have trolled yourself into the PLONK bin. Bye.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top