Re: Trouble with FILE



Ruud <Ruud.Baltissen@xxxxxx> writes:

Hallo allemaal,


I created a program where I opened a file to read from. For various
reasons I had to split up this program in several modules. Variables
declared in one module are made accessible to other modules using an h-
file. The troubleshooter in this case are some file pointers to open
several files at the same time for reading or writing. I can declare,
let's say, an integer in a module as "int Counter;" and then as
"extern int Counter;" in the h-file. But for one or another reason
that doesn't work for "FILE *fp1;". The documentation I have has only
examples where FILE is only used in one module.

I don't quite understand your description. The usual approach is to have

extern FILE *fp1;

in a header (.h) file which is included into your source (.c) files, and
then

FILE *fp1;

in exactly one of your .c files. Also, make sure that <stdio.h> is
included in the header file, so that the FILE type is defined.

When you say "that doesn't work", what exactly do you mean? What
happens? If there's an error message, what exactly does it say?

By the way, you might find

http://www.catb.org/~esr/faqs/smart-questions.html

helpful in framing questions to get good answers.
.



Relevant Pages

  • Re: Exported function mangaled name
    ... that header file; it must be declared as __declspec ... You have to declare the function the same way in your .cpp file as in ... #define LIBSPEC __declspec ... See my essay on The Ultimate DLL Header File on my MVP Tips site. ...
    (microsoft.public.vc.mfc)
  • Re: make general windows module
    ... The VB version of these declarations is the "Declare Statement". ... mimicing the behavior of a "windows.h" header file for VB. ... not all Windows API calls can be called from VB as some use reference ...
    (microsoft.public.vb.general.discussion)
  • Re: confused about extern use
    ... going to achieve by declaring it as extern in the header file a.h. ... composed on one or more compilation units. ... Essentially you *declare* the type wherever it is ...
    (comp.lang.c)
  • Re-forward declaration of types which were already forward declared
    ... Is it a good style to re-forward declare the types, ... forward declared in base header file, in derived class header file? ...
    (comp.lang.cpp)