473,842 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to create header files in c/c++

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

kind regards,

Jos
Oct 4 '08 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
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
dumparun
26 New Member
thats interesting to know..
thanks ...
Oct 6 '08 #8
JosAH
11,448 Recognized Expert MVP
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 New Member
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

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

Similar topics

16
12554
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 because it is, as the authors love to say, "implementation specific". If that's the case, how does the compiler commonly handle them? I use Linux and gcc specifically. Basically, I don't understand how a header file being included makes a...
18
2761
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 (collection of files) which are not required, except for one header file's contents. I'd say 'No, header files should be included in the C source, not in another
18
3598
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 creating a header file when compiling? Do I need to write in the block the #include (s)?
6
3697
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 the document to my clients so that they could use it to. I know most of them use Outlook XP or Outlook 2003, so what I created was a page that creates a Visual Basic script that, when saved to the desktop and
5
6783
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 cause. If I could create a large file that could be encrypted, and maybe add files to it by appending them and putting in some kind of delimiter between files, maybe a homemade version of truecrypt could be constructed. Any idea what it...
5
2421
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 Birthday is a class and Birthday paradox is mainly the driver for it. I am trying to create an object of Birthday in BirthdayParadox and it is not working. I get the error: "'Birthday' undeclared (first use this function)"
23
7441
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 in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
1
1723
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 is half written in C and the other half in C++. What were the developers thinking !?! I am using Visual Studio 2005 and to create the dll, I ran New Project -Win32 Project -Application Settings -> DLL (plus the additional option of exporting...
15
5287
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 show - text boxes, input boxes, buttons, hyperlinks ie the usual. The data is not obtained directly from a database.
2
2786
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 uploads, to the clients accounts. I have seen similar sites everywhere, such as bank websites, USPS site, et cetera. What is required to accomplish this? I'm trying to do this with the PHP, MySQL and Adobe CS3 Master collection's 'Dreamweaver CS3' ...
0
9865
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10934
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10609
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10668
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10303
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7025
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4085
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3140
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.