- Unable to open include file 'stdio.h'
- Posted by Brian Simms on April 24th, 2005
Hey there!
First of all forgive me if this question has already been asked and
answered, if it has can you direct me to the posting, I would really
appreciate that!
I have just installed Borland's C/C++ compiler and going to the First C
Tutorial in About. com, I typed in the program and went to compile it. When
I did I got the following Error messages:
Error E2209 hello.cpp1: Unable to open include file 'stdio.h'
Error E2268 hello.cpp4 Call to undefined function 'printf' in function
main()
I was wondering if someone can inform me as to what I am doing wrong and how
to rectify this.
I thank you all in advance for any help! BTW, I am running Windows XP
TIA
Brian
- Posted by codigo on April 24th, 2005
"Brian Simms" <besimms@xtra.co.nz> wrote in message
news:BLDae.978$Od6.145091@news.xtra.co.nz...
Perhaps the wrong library is specified for that compiler. You can check the
compiler's lib directory for what is available (maybe: cstdio?) Can you try
to compile this instead, its %100 standard C++ compliant:
#include <iostream>
using std::cout;
int main()
{
cout << "Hello World !\n";
}
You haven't specified whether its C++ or C you wish to learn.
- Posted by Jens.Toerring@physik.fu-berlin.de on April 24th, 2005
Brian Simms <besimms@xtra.co.nz> wrote:
First of all, from the choice of your file name (hello.cpp) it looks
as if you are reading a C++ tutorial, but your inclusion of 'stdio.h'
makes it look as if you are trying to learn C. While both languages
have a some similarities, they are different languages and shouldn't
be taken to be the same. Moreover, many compilers will automatically
switch to C++ mode when the file has an extension like '.cpp', which
can lead to trouble when what you want to compile is actually C code.
So always give C files an extension of '.c'.
From the inclusion of 'stdio.h' and the error message about the
missing definition of 'printf' I assume you are reading the C
tutorial. One possible reason, beside the accidental use of the
C++ compiler mode due to the wrong file exension, for your problem
could be a incorrectly installed compiler or a typo in the code.
It might be a good idea to post the code - it should be small enough.
I would recommend _not_ use the C tutorial at about.com. It already
has a major blunder in the very first example program and is obviously
not teaching you correct C. The function main() in a C program must
always return an integer (that's mandated by the C standard) and must
have one of the following forms:
int main( void )
or
int main( int argc, char *argv[ ] )
where the second argument 'char *argv[ ]' can also be written as
'char **argv' (and the names of the arguments 'argc' and 'argv'
can be renamed to whatever you fancy). Using something like
void main( )
is, while often found in code and accepted by many compilers, not
valid C. Later in the tutorial there are more problems (I stopped
reading when it talks about the gets() function without immediately
telling that you should never, ever use that function since it's
broken by design - a tutorial should either not mention that function
at all or only to warn the reader never to use it). I strongly re-
commend that you get a good book about C (like Kernighan and Ritchie's
"The C programming Language") - there are too many badly broken
"tutorials" out there in the wild and for someone who doesn't already
know C it's impossible to figure out which of them are good and which
are bad. The tutorial from about.com definitely seems to fall into the
later category.
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
- Posted by Chris Saunders on April 24th, 2005
I know C but am not an expert. Out of curiosity
what is the problem with gets()?
Regards
Chris Saunders
<Jens.Toerring@physik.fu-berlin.de> wrote in message
news:3d1a6hF6lsj46U1@uni-berlin.de...
snipped a bunch here
- Posted by Jens.Toerring@physik.fu-berlin.de on April 24th, 2005
Chris Saunders <chris.saunders@sympatico.ca> wrote:
You can't tell gets() the length of the buffer you pass to it and
gets() will happily write beyond the end of the buffer if there's
more input then fits into it, so it's a buffer overrun waiting to
happen with no way to circumvent the problem. The only time gets()
can be used safely is when one already knows in advance how long
the input going to be, a situation you won't encounter when dealing
with user input (and rarely at other times) - but in that tutorial
they use it for exactly that purpose all the time while there are
other functions like fgets() that don't have this particular problem.
Sometime later they write:
The function gets makes no check on the array size to see if
it is large enough to hold the string entered. It is up to the
programmer to create a character array that is large enough. (...)
This weakness in the C language can lead to program bugs.
which obviously is BS - first of all, gets() can't do any checks on
the size of the array it gets passed - that's simply not possible
since the function only gets a pointer to the first element (that's
why it's broken by design). Second, the programmer can't know in
advance how long the string is going to be, so he can't supply gets()
with a buffer large enough, and, finally, it's not a weakness of C
but of this particular function which they shouldn't have talked
about in the first place (or only to tell the reader not to forget
to never use it). On the other hand they don't even mention fgets()...
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de
- Posted by Joe Wright on April 24th, 2005
Chris Saunders wrote:
The notorious gets(buf) will read an unknown number of characters from
stdin until '\n' and place them in buf. How long is buf?
Therefore gets can overrun buf. There is no way to stop it. Malicious
programmers can use this characteristic to 'infect' programs.
Most recommend fgets for reading stdin as it is more controllable.
--
Joe Wright mailto:joewwright@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
- Posted by Brian Simms on April 25th, 2005
Hi guys!
First of all thank you for all your replies, I greatly appreciate it! Here
is the source code for you to analyse and see where I have screwed up:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
I am using the free version of Borlands C\C++ compiler (version 5.5) and
have created the "bcc32.cfg" file (it is a text file created in Notepad, is
that correct or did I screw that up?) also I have created an "ilink32.cfg"
file (again as a text file via Notepad) These are both stored in the
following Directory: C:\Borlands\BCC55\Bin (as per the instructions on
Borlands website).
The above program is stored in the Directory "C:\mycodes" with the following
filename: hello.c
I open the Command prompt and change to the directory: C:\mycodes.
At the prompt (which now is "C:\mycodes>" I type in "bcc32 hello.c" after
which I get the following message:
Borland C++ 5.5.1 for Win32 Copyright <c> 1993, 2000 Borland
hello.c:
Error E2209 hello.c 1: Unable to open include file 'stdio.h'
Warning W8065 hello.c 4: Call to function 'printf' with no prototype in
function main
*** 1 errors in Compile ***
- Posted by Jens.Toerring@physik.fu-berlin.de on April 27th, 2005
Brian Simms <besimms@xtra.co.nz> wrote:
int main(void)
to indicate that main() does not take an argument (instead of an
unspecified number of arguments) would be the correct thing to
do it.
This program looks ok (it could use some reasonable indentation, but
you will get to that once you start writing longer programs;-).
Sorry, can't really help you there since I never used Borlands C/C++...
A short look at the Borland web page seems to indicate that you may need
a command line like
bcc32 -IC:\Borland\bcc55\include -LC:\Borland\bcc55\Lib hello.c
to explicitely tell the compiler where the include files and libraries
are to be found. But that's just a guess...
All that you need to care about is the error, the warning is just a
result of that error.
Regards, Jens
--
\ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de
\__________________________ http://www.toerring.de