Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Help with header file

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Estraik
Expert Cheater
Reputation: 0

Joined: 05 Feb 2008
Posts: 128

PostPosted: Thu Oct 09, 2008 6:42 am    Post subject: Help with header file Reply with quote

How do I start a header file in C++?

I want to know how to show it on the source code and how to call it.

Also would like to know what to include in the .h file:

Like, does it goes like the source code?

By that I mean:

If the header file need to have an:

int main() ?

Or if something else, what would it be? and how to end the header file?

And how to call it inside the source code?

Any help would be appreciated.
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Thu Oct 09, 2008 7:15 am    Post subject: Reply with quote

mything.h:
Code:
#ifndef _MYTHINGH
#define _MYTHINGH

#include <stdio.h>

// Functions, structures, classes, etc.
void StupidFunction();

#endif


mything.c:
Code:
// The actual functions.

void StupidFunction() {
  printf("Hello World!\n");
}


main.c:
Code:
#include "mything.h"

int main(int argc, char *argv[])
{
  StupidFunction();

  return 0;
}


EDIT: Added lil' more code (main.c).
EDIT: More more more.


Last edited by Jani on Thu Oct 09, 2008 7:23 am; edited 3 times in total
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Thu Oct 09, 2008 7:17 am    Post subject: Reply with quote

The header file usually contains function definitions, class definitions and so forth.

You can add a header file in MSVC++ clicking Add item -> Header file(.h).
Back to top
View user's profile Send private message MSN Messenger
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Thu Oct 09, 2008 9:19 am    Post subject: Reply with quote

Just so you know, the header file could contain anything another file contains.
So you could write your whole program in the headerfile if you wanted to, but that's not the purpose of it.
You could also write programs without header files. Most of my programs are small and have no header files, and only a 'main.cpp'.
Back to top
View user's profile Send private message
_TheChosen_
Advanced Cheater
Reputation: 0

Joined: 13 Jul 2007
Posts: 50
Location: Oaxaca

PostPosted: Thu Oct 09, 2008 7:29 pm    Post subject: Reply with quote

A header files main purpose is re-usable code. Think everyone else explained everything else.
_________________
Ciento dos huevos.
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Thu Oct 09, 2008 11:47 pm    Post subject: Reply with quote

Header file should contain the code, .cpp file should contain all the declarations and constants, like this:

Code:

//foobar.c
#define MAX_POOP 10
#define ERROR_MESSAGE "You has an error!"
#include foobar.h


Code:

//foobar.h
int main()
{
//do stuff
}

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Fri Oct 10, 2008 2:10 am    Post subject: Reply with quote

Are you being sarcastic? (hope so)
It's exactly the other way around. The reason you put constants and stuff in the header file, is because when you include it in all your projects files and then want to change the constant, you only have to change it once in the header file.
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Tue Oct 14, 2008 12:16 am    Post subject: Reply with quote

You CAN do it my way though! You can even do

Code:
#include "afile.c"

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites