473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to create header files in c/c++

hi, i m sourabh....... Can any1 tell me how to create a header file in c/c++
Oct 4 '08 #1
10 1767
JosAH
11,448 Expert 8TB
Simply create a text file with the extension .h and voila.

kind regards,

Jos
Oct 4 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
The text file doesn't even need the .h you just need to #include the text file in your source file.
Oct 4 '08 #3
Tassos Souris
152 100+
Exactly what the above guys said...

A typical example of a header file named Example.h is:
Expand|Select|Wrap|Line Numbers
  1. #ifndef EXAMPLE_H
  2. #define EXAMPLE_H
  3.  
  4. /* make definitions, declarations here... */
  5.  
  6. #endif /* EXAMPLE_H */
  7.  
Note that if you want to be strictly ANSI the above code is wrong!!! Visual Studio gives an error and gcc a warning. And the reason is the last comment...
Oct 5 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
Note that if you want to be strictly ANSI the above code is wrong!!! Visual Studio gives an error and gcc a warning. And the reason is the last comment...
I'll bite. My Visual Studio sees no error.
Oct 5 '08 #5
Tassos Souris
152 100+
I'll bite. My Visual Studio sees no error.
Visual Studio gives an error as i said only with ANSI. You must put the /Za flag.

Specifically, the error is:
Expand|Select|Wrap|Line Numbers
  1. fatal error C1004: unexpected end-of-file found
  2.  
and that is because the logical source does not end with a new-line.. something like that..
Oct 5 '08 #6
weaknessforcats
9,208 Expert Mod 8TB
Yes, the file must end with a null record. That is, enter-key only.
I don't know exactly what the ANSI standard says about this.
Oct 5 '08 #7
thats interesting to know..
thanks ...
Oct 6 '08 #8
JosAH
11,448 Expert 8TB
Yes, the file must end with a null record. That is, enter-key only.
I don't know exactly what the ANSI standard says about this.
The C99 Standard:

5.1.1.2. Environment

A source file that is not empty
shall end in a new-line character, which shall not be
immediately preceded by a backslash character before
any such splicing takes place.
By 'splicing' they mean the trailing backslash immediately followed by a new-line
character which concatenates two physical lines.

kind regards,

Jos
Oct 6 '08 #9
Tassos Souris
152 100+
I actually thought this was a bug in Visual Studio 2008 and asked a friend to send a bug report; the answer we got amazed us!!! :-P
Oct 6 '08 #10
Banfa
9,065 Expert Mod 8TB
I worked on a multi-platform project once where a new platform was introduced and its compiler produced an error where source files did not end in new-line. The compilers on the 3 existing platforms did not produce an error or even a warning in this case so lots of the code files did not end in a new-line.

Some lucky person (not me) got the job of adding a new-line to the end of all the (several 100) source files.
Oct 6 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: matthurne | last post by:
I just started learning C++ on my own...I'm using Accelerated C++. Something it hasn't explained and I keep wondering about is how header files actually work. I suspect it doesn't get into it...
18
by: John Smith | last post by:
Hi all What does the group think of the practise of including one header file from inside another? I have some legacy code where this has been done, and it creates a dependency on a module...
18
by: Al | last post by:
I'm still trying to do this but it never worked! In a .cpp file, I write the code, and at the beginning, I write: #ifndef MYLIST_H #define MYLIST_H ....to end: #endif What's wrong with it for...
6
by: windandwaves | last post by:
Hi Folk Some of my clients asked me to create "fancy emails" for them (aka html formatted emails). I know how to make a nice html document, but I had trouble creating a simple way to provide...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
5
by: Willson | last post by:
Ok, first off I am learning C++ for the first time. I know Java very well, but a new class of mine requires C++. So bare with me please. I have 2 classes, Birthday.cpp and BirthdayParadox.cpp ...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
1
by: greg | last post by:
I used the same approach as the one described here: http://blogs.msdn.com/jonathanswift/archive/2006/10/02/780637.aspx The only catch is that the project which I am trying to compile into a dll...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
2
by: nja2222 | last post by:
I would like to create a page for my clients to login and check for updates on their accounts. Then I would like to create a page where my employees can login and make updates, specifically new file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.