I'm having trouble using my homemade .h files in my multi-source projects. If I I only include the .h in one of the sources I can't use it in the others. But if I include it other sources it's considered redefining the include and it won't compile. Other .h's besides the ones that I make do this to. I've noticed that some though (such as iostream) don't have this problem and I could include it in the same source 10 times if I wanted to. can someone please help me out with this so that I can make header files that can be declared more than once in the same project?

Recommended Answers

All 28 Replies

Stick this into all header files you create ever!


Note THISFILE_H should be a unique name such as the file's name.

#ifndef __THISFILE_H
#define __THISFILE_H

#ifdef __cplusplus
extern "C" {
#endif



// Insert your H definitions here


#ifdef __cplusplus
};
#endif

#endif		// __THISFILE_H

Possibly lack of code guards is the problem.

#ifndef MYHEADER_H
#define MYHEADER_H

// other stuff here
#endif

[edit]what ^^^ said [/edit]

I couldn't get wild gooses to work and ancient dragon, yours doesn't work over multiple source files in a project.

Post your header file. I suspect you are putting executable code or declaring objects in it. You can't do that. If you want to put an integer in the header file then you have to declare it with the extern keyword so that the compiler knows to look in a *.c or *.cpp file for it. extern int foo;

Does this look right wild goose?

#ifndef __hello_H
#define __hello_H

#ifdef __cplusplus
extern "C" {
#endif

// Insert your H definitions here


#include <iostream>
using namespace std;

void hi();

void hi()
{
     cout << "Hi!";
     return;
}


#ifdef __cplusplus
};
#endif

oh I was declaring functions. that would explain it.

Did you use a different definiton name for each header file?

It should have worked. This methodology is used in projects containing thousands of files! What are your exact error(s).
C/CPP files #include each H file? or are nested to contain other H files?

Just as I thought -- you have to move that function into a *.cpp file.

simultaneous postings!

Yep, Get the function out of the header. Only their definitions (for now) should be there!

get the namespace out of there too! Should be in the C++ file near the top.

Ok! These simultaneous postings are confusing me!
Here is what I have so far. Please tell me what's wrong.

HEADER:

#ifndef __hello_H
#define __hello_H
 
#ifdef __cplusplus
extern "C" {
#endif
 
// Insert your H definitions here
 
 
#include <iostream>
 
void hi()
{
     std::cout << "Hi!" << std::cout;
     return;
}
 
 
#ifdef __cplusplus
};
#endif

FIRST .CPP FILE:
#include "hello.h"
#include "hello.h" //YES i WANT THIS HERE AS A TEST

void hi();

int main()
{
    hi();
    system("pause");
    return 0;
}
    
SECOND .CPP FILE:
#include "hello.h"

void hi();

int main()
{
    hi();
    system("pause");
    return 0;
}

Ok! These simultaneous postings are confusing me! Do either of you know what is wrong with this.
HEADER:

#ifndef __hello_H
#define __hello_H
 
#ifdef __cplusplus
extern "C" {
#endif
 
// Insert your H definitions here
 
 
#include <iostream>
 
void hi()
{
     std::cout << "Hi!" << std::cout;
     return;
}
 
 
#ifdef __cplusplus
};
#endif

1ST .CPP

#include "hello.h"

void hi();

int main()
{
    hi();
    system("pause");
    return 0;
}

2ND .CPP

#include "hello.h"
#include "hello.h" //I'M DOING THIS AS A TEST

void hi();

int main()
{
    hi();
    system("pause");
    return 0;
}

By the way I don't know if this matters but I use dev.

#ifndef __hello_H
#define __hello_H

#ifdef __cplusplus
extern "C" {
#endif


void hi();


#ifdef __cplusplus
};
#endif

ANY other C++ file

#include <iostream>
#include "hello.h"


int main()
{
hi();
system("pause");
return 0;
}

Slight error on the C++ file. Forgot the function

#include <iostream>
#include "hello.h"


int main()
{
hi();
system("pause");
return 0;
} 
#include <iostream>
#include "hello.h"


int main()
{
hi();
system("pause");
return 0;
} 



void hi()
{
std::cout << "Hi!" << std::cout;
return;
}

Let's try this again. ITTY BITTY EDitting window.

#include <iostream>
#include "hello.h"


int main()
{
hi();
system("pause");
return 0;
} 



void hi()
{
std::cout << "Hi!" << std::cout;
return;
}

Is there a way I can define the function in the header file(I write big functions)?

Yes, it is okay to define some functions/methods in a header file but you don't want to go there yet as it will just get you more confused. If I haven't blown it myself the general rules would be functions/methods to be declared inline can be defined in the header file (particularly if the function body is only 1 or 2 lines long) and methods/functions declared as a template must be defined in the header file; otherwise, most functions/methods should be defined in a .cpp file of the same name as the header file that they are declared in.

Ditto! As to what Lerner said!

There's a time and place for static functions, but remember, you want you H files to be light and easily viewable. You don't want to have to parse them looking for something as you would in your C/C++ file.

Well how would I incorperate a function like this into a header file and have it defined there? I don't want to have to keep typing this everytime I use it in a program.(By the way, this is one of my smaller
functions.

void Color(string colorB, string colorF) // in front of the function definition
{


    if(colorB == "black" && colorF == "black")
        system("color 00");
    if(colorB == "bwhite" && colorF == "black")
        system("color F0");
    if(colorB == "white" && colorF == "black")
        system("color 70");
    if(colorB == "gray" && colorF == "black")
        system("color 80");
    if(colorB == "red" && colorF == "black")
        system("color 40");
    if(colorB == "blue" && colorF == "black")
        system("color 10");
    if(colorB == "yellow" && colorF == "black")
        system("color 60");
    if(colorB == "green" && colorF == "black")
        system("color 20");
    if(colorB == "purple" && colorF == "black")
        system("color 50");
    if(colorB == "aqua" && colorF == "black")
        system("color 30");
    if(colorB == "lred" && colorF == "black")
        system("color C0");
    if(colorB == "lblue" && colorF == "black")
        system("color 90");
    if(colorB == "lyellow" && colorF == "black")
        system("color E0");
    if(colorB == "lgreen" && colorF == "black")
        system("color A0");
    if(colorB == "lpurple" && colorF == "black")
        system("color D0");
    if(colorB == "laqua" && colorF == "black")
        system("color B0");
    
    if(colorB == "black" && colorF == "bwhite")
        system("color 0F");
    if(colorB == "bwhite" && colorF == "bwhite")
        system("color FF");
    if(colorB == "white" && colorF == "bwhite")
        system("color 7F");
    if(colorB == "gray" && colorF == "bwhite")
        system("color 8F");
    if(colorB == "red" && colorF == "bwhite")
        system("color 4F");
    if(colorB == "blue" && colorF == "bwhite")
        system("color 1F");
    if(colorB == "yellow" && colorF == "bwhite")
        system("color 6F");
    if(colorB == "green" && colorF == "bwhite")
        system("color 2F");
    if(colorB == "purple" && colorF == "bwhite")
        system("color 5F");
    if(colorB == "aqua" && colorF == "bwhite")
        system("color 3F");
    if(colorB == "lred" && colorF == "bwhite")
        system("color CF");
    if(colorB == "lblue" && colorF == "bwhite")
        system("color 9F");
    if(colorB == "lyellow" && colorF == "bwhite")
        system("color EF");
    if(colorB == "lgreen" && colorF == "bwhite")
        system("color AF");
    if(colorB == "lpurple" && colorF == "bwhite")
        system("color DF");
    if(colorB == "laqua" && colorF == "bwhite")
        system("color BF");
    
    if(colorB == "black" && colorF == "white")
        system("color 07");
    if(colorB == "bwhite" && colorF == "white")
        system("color F7");
    if(colorB == "white" && colorF == "white")
        system("color 77");
    if(colorB == "gray" && colorF == "white")
        system("color 87");
    if(colorB == "red" && colorF == "white")
        system("color 47");
    if(colorB == "blue" && colorF == "white")
        system("color 17");
    if(colorB == "yellow" && colorF == "white")
        system("color 67");
    if(colorB == "green" && colorF == "white")
        system("color 27");
    if(colorB == "purple" && colorF == "white")
        system("color 57");
    if(colorB == "aqua" && colorF == "white")
        system("color 37");
    if(colorB == "lred" && colorF == "white")
        system("color C7");
    if(colorB == "lblue" && colorF == "white")
        system("color 97");
    if(colorB == "lyellow" && colorF == "white")
        system("color E7");
    if(colorB == "lgreen" && colorF == "white")
        system("color A7");
    if(colorB == "lpurple" && colorF == "white")
        system("color D7");
    if(colorB == "laqua" && colorF == "white")
        system("color B7");
    
    if(colorB == "black" && colorF == "gray")
        system("color 08");
    if(colorB == "bwhite" && colorF == "gray")
        system("color F8");
    if(colorB == "white" && colorF == "gray")
        system("color 78");
    if(colorB == "gray" && colorF == "gray")
        system("color 88");
    if(colorB == "red" && colorF == "gray")
        system("color 48");
    if(colorB == "blue" && colorF == "gray")
        system("color 18");
    if(colorB == "yellow" && colorF == "gray")
        system("color 68");
    if(colorB == "green" && colorF == "gray")
        system("color 28");
    if(colorB == "purple" && colorF == "gray")
        system("color 58");
    if(colorB == "aqua" && colorF == "gray")
        system("color 38");
    if(colorB == "lred" && colorF == "gray")
        system("color C8");
    if(colorB == "lblue" && colorF == "gray")
        system("color 98");
    if(colorB == "lyellow" && colorF == "gray")
        system("color E8");
    if(colorB == "lgreen" && colorF == "gray")
        system("color A8");
    if(colorB == "lpurple" && colorF == "gray")
        system("color D8");
    if(colorB == "laqua" && colorF == "gray")
        system("color B8");
        
    if(colorB == "black" && colorF == "red")
        system("color 04");
    if(colorB == "bwhite" && colorF == "red")
        system("color F4");
    if(colorB == "white" && colorF == "red")
        system("color 74");
    if(colorB == "gray" && colorF == "red")
        system("color 84");
    if(colorB == "red" && colorF == "red")
        system("color 44");
    if(colorB == "blue" && colorF == "red")
        system("color 14");
    if(colorB == "yellow" && colorF == "red")
        system("color 64");
    if(colorB == "green" && colorF == "red")
        system("color 24");
    if(colorB == "purple" && colorF == "red")
        system("color 54");
    if(colorB == "aqua" && colorF == "red")
        system("color 34");
    if(colorB == "lred" && colorF == "red")
        system("color C4");
    if(colorB == "lblue" && colorF == "red")
        system("color 94");
    if(colorB == "lyellow" && colorF == "red")
        system("color E4");
    if(colorB == "lgreen" && colorF == "red")
        system("color A4");
    if(colorB == "lpurple" && colorF == "red")
        system("color D4");
    if(colorB == "laqua" && colorF == "red")
        system("color B4");
    
    if(colorB == "black" && colorF == "blue")
        system("color 01");
    if(colorB == "bwhite" && colorF == "blue")
        system("color F1");
    if(colorB == "white" && colorF == "blue")
        system("color 71");
    if(colorB == "gray" && colorF == "blue")
        system("color 81");
    if(colorB == "red" && colorF == "blue")
        system("color 41");
    if(colorB == "blue" && colorF == "blue")
        system("color 11");
    if(colorB == "yellow" && colorF == "blue")
        system("color 61");
    if(colorB == "green" && colorF == "blue")
        system("color 21");
    if(colorB == "purple" && colorF == "blue")
        system("color 51");
    if(colorB == "aqua" && colorF == "blue")
        system("color 31");
    if(colorB == "lred" && colorF == "blue")
        system("color C1");
    if(colorB == "lblue" && colorF == "blue")
        system("color 91");
    if(colorB == "lyellow" && colorF == "blue")
        system("color E1");
    if(colorB == "lgreen" && colorF == "blue")
        system("color A1");
    if(colorB == "lpurple" && colorF == "blue")
        system("color D1");
    if(colorB == "laqua" && colorF == "blue")
        system("color B1");
    
        if(colorB == "black" && colorF == "yellow")
        system("color 06");
    if(colorB == "bwhite" && colorF == "yellow")
        system("color F6");
    if(colorB == "white" && colorF == "yellow")
        system("color 76");
    if(colorB == "gray" && colorF == "yellow")
        system("color 86");
    if(colorB == "red" && colorF == "yellow")
        system("color 46");
    if(colorB == "blue" && colorF == "yellow")
        system("color 16");
    if(colorB == "yellow" && colorF == "yellow")
        system("color 66");
    if(colorB == "green" && colorF == "yellow")
        system("color 26");
    if(colorB == "purple" && colorF == "yellow")
        system("color 56");
    if(colorB == "aqua" && colorF == "yellow")
        system("color 36");
    if(colorB == "lred" && colorF == "yellow")
        system("color C6");
    if(colorB == "lblue" && colorF == "yellow")
        system("color 96");
    if(colorB == "lyellow" && colorF == "yellow")
        system("color E6");
    if(colorB == "lgreen" && colorF == "yellow")
        system("color A6");
    if(colorB == "lpurple" && colorF == "yellow")
        system("color D6");
    if(colorB == "laqua" && colorF == "yellow")
        system("color B6");
    
    if(colorB == "black" && colorF == "green")
        system("color 02");
    if(colorB == "bwhite" && colorF == "green")
        system("color F2");
    if(colorB == "white" && colorF == "green")
        system("color 72");
    if(colorB == "gray" && colorF == "green")
        system("color 82");
    if(colorB == "red" && colorF == "green")
        system("color 42");
    if(colorB == "blue" && colorF == "green")
        system("color 12");
    if(colorB == "yellow" && colorF == "green")
        system("color 62");
    if(colorB == "green" && colorF == "green")
        system("color 22");
    if(colorB == "purple" && colorF == "green")
        system("color 52");
    if(colorB == "aqua" && colorF == "green")
        system("color 32");
    if(colorB == "lred" && colorF == "green")
        system("color C2");
    if(colorB == "lblue" && colorF == "green")
        system("color 92");
    if(colorB == "lyellow" && colorF == "green")
        system("color E2");
    if(colorB == "lgreen" && colorF == "green")
        system("color A2");
    if(colorB == "lpurple" && colorF == "green")
        system("color D2");
    if(colorB == "laqua" && colorF == "green")
        system("color B2");

    if(colorB == "black" && colorF == "purple")
        system("color 05");
    if(colorB == "bwhite" && colorF == "purple")
        system("color F5");
    if(colorB == "white" && colorF == "purple")
        system("color 75");
    if(colorB == "gray" && colorF == "purple")
        system("color 85");
    if(colorB == "red" && colorF == "purple")
        system("color 45");
    if(colorB == "blue" && colorF == "purple")
        system("color 15");
    if(colorB == "yellow" && colorF == "purple")
        system("color 65");
    if(colorB == "green" && colorF == "purple")
        system("color 25");
    if(colorB == "purple" && colorF == "purple")
        system("color 55");
    if(colorB == "aqua" && colorF == "purple")
        system("color 35");
    if(colorB == "lred" && colorF == "purple")
        system("color C5");
    if(colorB == "lblue" && colorF == "purple")
        system("color 95");
    if(colorB == "lyellow" && colorF == "purple")
        system("color E5");
    if(colorB == "lgreen" && colorF == "purple")
        system("color A5");
    if(colorB == "lpurple" && colorF == "purple")
        system("color D5");
    if(colorB == "laqua" && colorF == "purple")
        system("color B5");
    
    if(colorB == "black" && colorF == "aqua")
        system("color 03");
    if(colorB == "bwhite" && colorF == "aqua")
        system("color F3");
    if(colorB == "white" && colorF == "aqua")
        system("color 73");
    if(colorB == "gray" && colorF == "aqua")
        system("color 83");
    if(colorB == "red" && colorF == "aqua")
        system("color 43");
    if(colorB == "blue" && colorF == "aqua")
        system("color 13");
    if(colorB == "yellow" && colorF == "aqua")
        system("color 63");
    if(colorB == "green" && colorF == "aqua")
        system("color 23");
    if(colorB == "purple" && colorF == "aqua")
        system("color 53");
    if(colorB == "aqua" && colorF == "aqua")
        system("color 33");
    if(colorB == "lred" && colorF == "aqua")
        system("color C3");
    if(colorB == "lblue" && colorF == "aqua")
        system("color 93");
    if(colorB == "lyellow" && colorF == "aqua")
        system("color E3");
    if(colorB == "lgreen" && colorF == "aqua")
        system("color A3");
    if(colorB == "lpurple" && colorF == "aqua")
        system("color D3");
    if(colorB == "laqua" && colorF == "aqua")
        system("color B3");
    
    if(colorB == "black" && colorF == "lred")
        system("color 0C");
    if(colorB == "bwhite" && colorF == "lred")
        system("color FC");
    if(colorB == "white" && colorF == "lred")
        system("color 7C");
    if(colorB == "gray" && colorF == "lred")
        system("color 8C");
    if(colorB == "red" && colorF == "lred")
        system("color 4C");
    if(colorB == "blue" && colorF == "lred")
        system("color 1C");
    if(colorB == "yellow" && colorF == "lred")
        system("color 6C");
    if(colorB == "green" && colorF == "lred")
        system("color 2C");
    if(colorB == "purple" && colorF == "lred")
        system("color 5C");
    if(colorB == "aqua" && colorF == "lred")
        system("color 3C");
    if(colorB == "lred" && colorF == "lred")
        system("color CC");
    if(colorB == "lblue" && colorF == "lred")
        system("color 9C");
    if(colorB == "lyellow" && colorF == "lred")
        system("color EC");
    if(colorB == "lgreen" && colorF == "lred")
        system("color AC");
    if(colorB == "lpurple" && colorF == "lred")
        system("color DC");
    if(colorB == "laqua" && colorF == "lred")
        system("color BC");
    
    if(colorB == "black" && colorF == "lblue")
        system("color 09");
    if(colorB == "bwhite" && colorF == "lblue")
        system("color F9");
    if(colorB == "white" && colorF == "lblue")
        system("color 79");
    if(colorB == "gray" && colorF == "lblue")
        system("color 89");
    if(colorB == "red" && colorF == "lblue")
        system("color 49");
    if(colorB == "blue" && colorF == "lblue")
        system("color 19");
    if(colorB == "yellow" && colorF == "lblue")
        system("color 69");
    if(colorB == "green" && colorF == "lblue")
        system("color 29");
    if(colorB == "purple" && colorF == "lblue")
        system("color 59");
    if(colorB == "aqua" && colorF == "lblue")
        system("color 39");
    if(colorB == "lred" && colorF == "lblue")
        system("color C9");
    if(colorB == "lblue" && colorF == "lblue")
        system("color 99");
    if(colorB == "lyellow" && colorF == "lblue")
        system("color E9");
    if(colorB == "lgreen" && colorF == "lblue")
        system("color A9");
    if(colorB == "lpurple" && colorF == "lblue")
        system("color D9");
    if(colorB == "laqua" && colorF == "lblue")
        system("color B9");
        
    if(colorB == "black" && colorF == "lyellow")
        system("color 0E");
    if(colorB == "bwhite" && colorF == "lyellow")
        system("color FE");
    if(colorB == "white" && colorF == "lyellow")
        system("color 7E");
    if(colorB == "gray" && colorF == "lyellow")
        system("color 8E");
    if(colorB == "red" && colorF == "lyellow")
        system("color 4E");
    if(colorB == "blue" && colorF == "lyellow")
        system("color 1E");
    if(colorB == "yellow" && colorF == "lyellow")
        system("color 6E");
    if(colorB == "green" && colorF == "lyellow")
        system("color 2E");
    if(colorB == "purple" && colorF == "lyellow")
        system("color 5E");
    if(colorB == "aqua" && colorF == "lyellow")
        system("color 3E");
    if(colorB == "lred" && colorF == "lyellow")
        system("color CE");
    if(colorB == "lblue" && colorF == "lyellow")
        system("color 9E");
    if(colorB == "lyellow" && colorF == "lyellow")
        system("color EE");
    if(colorB == "lgreen" && colorF == "lyellow")
        system("color AE");
    if(colorB == "lpurple" && colorF == "lyellow")
        system("color DE");
    if(colorB == "laqua" && colorF == "lyellow")
        system("color BE");
    
    if(colorB == "black" && colorF == "lgreen")
        system("color 0A");
    if(colorB == "bwhite" && colorF == "lgreen")
        system("color FA");
    if(colorB == "white" && colorF == "lgreen")
        system("color 7A");
    if(colorB == "gray" && colorF == "lgreen")
        system("color 8A");
    if(colorB == "red" && colorF == "lgreen")
        system("color 4A");
    if(colorB == "blue" && colorF == "lgreen")
        system("color 1A");
    if(colorB == "yellow" && colorF == "lgreen")
        system("color 6A");
    if(colorB == "green" && colorF == "lgreen")
        system("color 2A");
    if(colorB == "purple" && colorF == "lgreen")
        system("color 5A");
    if(colorB == "aqua" && colorF == "lgreen")
        system("color 3A");
    if(colorB == "lred" && colorF == "lgreen")
        system("color CA");
    if(colorB == "lblue" && colorF == "lgreen")
        system("color 9A");
    if(colorB == "lyellow" && colorF == "lgreen")
        system("color EA");
    if(colorB == "lgreen" && colorF == "lgreen")
        system("color AA");
    if(colorB == "lpurple" && colorF == "lgreen")
        system("color DA");
    if(colorB == "laqua" && colorF == "lgreen")
        system("color BA");
    
        if(colorB == "black" && colorF == "lpurple")
        system("color 0D");
    if(colorB == "bwhite" && colorF == "lpurple")
        system("color FD");
    if(colorB == "white" && colorF == "lpurple")
        system("color 7D");
    if(colorB == "gray" && colorF == "lpurple")
        system("color 8D");
    if(colorB == "red" && colorF == "lpurple")
        system("color 4D");
    if(colorB == "blue" && colorF == "lpurple")
        system("color 1D");
    if(colorB == "yellow" && colorF == "lpurple")
        system("color 6D");
    if(colorB == "green" && colorF == "lpurple")
        system("color 2D");
    if(colorB == "purple" && colorF == "lpurple")
        system("color 5D");
    if(colorB == "aqua" && colorF == "lpurple")
        system("color 3D");
    if(colorB == "lred" && colorF == "lpurple")
        system("color CD");
    if(colorB == "lblue" && colorF == "lpurple")
        system("color 9D");
    if(colorB == "lyellow" && colorF == "lpurple")
        system("color ED");
    if(colorB == "lgreen" && colorF == "lpurple")
        system("color AD");
    if(colorB == "lpurple" && colorF == "lpurple")
        system("color DD");
    if(colorB == "laqua" && colorF == "lpurple")
        system("color BD");
    
    if(colorB == "black" && colorF == "laqua")
        system("color 0B");
    if(colorB == "bwhite" && colorF == "laqua")
        system("color FB");
    if(colorB == "white" && colorF == "laqua")
        system("color 7B");
    if(colorB == "gray" && colorF == "laqua")
        system("color 8B");
    if(colorB == "red" && colorF == "laqua")
        system("color 4B");
    if(colorB == "blue" && colorF == "laqua")
        system("color 1B");
    if(colorB == "yellow" && colorF == "laqua")
        system("color 6B");
    if(colorB == "green" && colorF == "laqua")
        system("color 2B");
    if(colorB == "purple" && colorF == "laqua")
        system("color 5B");
    if(colorB == "aqua" && colorF == "laqua")
        system("color 3B");
    if(colorB == "lred" && colorF == "laqua")
        system("color CB");
    if(colorB == "lblue" && colorF == "laqua")
        system("color 9B");
    if(colorB == "lyellow" && colorF == "laqua")
        system("color EB");
    if(colorB == "lgreen" && colorF == "laqua")
        system("color AB");
    if(colorB == "lpurple" && colorF == "laqua")
        system("color DB");
    if(colorB == "laqua" && colorF == "laqua")
        system("color BB");
    if(colorB == "?" || colorF == "?")
        cout << "Black = black\nBlue = blue\nGreen = green\nAqua = aqua\nRed = red\nPurple = purple\nYellow = yellow\nWhite = white\nGray = gray\nLight Blue = lblue\nLight Green = lgreen\nLight Aqua = laqua\nLight Red = lred\nLight Purple = lpurple\nLight Yellow = lyellow\nBright White = bwhite\n";  
return;
}

LOT's of ELSE IF's.

Just kidding!

How about associating an enum to the color noun.
Then using a table lookup?

would maybe trying to make this a resource file work?

table lookup!!!!!
I'm not going to build the whole program for you, but this is a giant step!

unsigned char ColorAry[ iCOLOR_MAX ] [ iCOLOR_MAX ] =
{      //  Black,  BWhite,  White, Gray, Red,     etc.
     {  0x00,                         },    // Black
     {  0xF0,                          },   // BWhite
     {  0x70,                          },   // White
                etc.
};


typedef enum iCOLOR
{
    iCOLOR_BLACK = 0,
    iCOLOR_BWHITE,
    iCOLOR_WHITE,
    iCOLOR_GRAY,
    iCOLOR_RED,
    iCOLOR_BLUE,
    iCOLOR_YELLOW,
    iCOLOR_GREEN,
    iCOLOR_PURPLE,
    iCOLOR_AQUA,
    iCOLOR_LRED,
    iCOLOR_LBLUE,
    iCOLOR_LYELLOW,
    iCOLOR_LGREEN,
    iCOLOR_LPURPLE,
    iCOLOR_LAQUA,
        // Insert new colors above this line!
    iCOLOR_MAX
};





iCOLOR GetColorId( char *szColor )
{
     if (!stricmp( szColor, "BLACK" );
     {
           return iCOLOR_BLACK;
     }
    else if (!stricmp(


sprintf( szBuf, "color%2.2x", ColorAry[ nCol ], [ nRow ] );

Make sure the iCOLOR enums are before the array!
I goofed and put it afterwards!

One of the benefits about .h files is that you can include them in mulitple projects without having to retype the declaration each time. The linker will look up the definition/implementation each time you include it somewhere. Another benefit is that if you want to change the implementation you only have to rewrite the definition once, as long as the interface/declaration doesn't change.

Ok. Thank you. But I have many other functions to that are much longer than this. I hate having to redefine those functions every time.
is there a way to put this stuff in a header or resource file?

Put each Functional type into its own CPP file and have a matching H file as a matching set. then merely include the H file.

As to your other note. Programming is an art. You examine the problem and think of the most flexible solution to solve that problem. It needs to be eligant, readable, clean, functional, and easily modifiable. There are other adjectives but these are the highlights.

A good file size is about 1000 lines of code. When it gets around 2000 try to think about how to subdivide it into something more manageable. And then organize the files. A video game has millions of lines of code.

Oh, and just don't start writing huge functions. Think on the function is there another way of representing the data thus an alternate way of solving the problem.

That one function you shown was a case of reuse. Reuse means things can be condensed, and arrays are great for condensing. I also noted that the "color##" strings used the same characters as represented by Hex and were always two digits. So no need for strings, merely a single byte to store each hex code. If it wasn't in hex, then a secondary lookup table, or merely a suffix string appended to a pre-string of "color".

Thanks a lot for all of your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.