Hi,
Is it necessary to include header files at the top? Coz i tried not including the ctype.h and string.h and still use their functions with success.
thnx
Hi,
Is it necessary to include header files at the top? Coz i tried not including the ctype.h and string.h and still use their functions with success.
thnx
Well, in some compilers, not including header files sometimes works for frequently used functions. But always include the necessary header files as a good programming practice.
The experimenter who does not know what he is looking for will not understand what he finds.
- Claude Bernard
i asked this question because i am currently up the the character and strings part and i got mixed up with which functions in the string.h and which are in the ctype.h ?
Always include header-files, just like ozgulker said. If you don't, than it can happen that some compiler won't compile your code because it can't find some definitions.
The header-files are stored in some include-directory. There you can find them and read them.
> Is it necessary to include header files at the top?
It is only strictly necessary to include a file at some point before your first use of some declaration inside that file.
So theoretically, you could have them spread thoughout the code.
However, one of the things which is useful to be able to do is work out which files a particular module is dependent upon (for say porting to another platform). This is much easier to do if all the includes are together at the start of a file, and much harder if they are scattered.
One important thing to note is that just because my compiler automatically includes stdio and stdlib when I compile doesn't mean that yours does. Keep in mind that you will probably use more than one compiler in your life time, so it is generally a good idea to make code that anyone can compile.