Header file

I am using Borland C++ 6 Enterprise and have just typed a project from my book. I now need to create a header file and my book does not say how to do it(even though it is a borland C++ book).

I have tried right clicking and it gives me an option to open Source/Header file but of course none is created yet. I have went to the 'new' Under file and selected other and cant find anything for a header file there.

The book I am working out of is "Teach Yourself Borland C++ Builder in 21 days"(please go easy on me for that). The project that I am working on is on Page 60, Day 2, 'Maillist.cpp'.

-BHill

I'm not familiar with Borland (I didn't think anyone still used it =x), but such options are typically in one of a few places:

- In the "Project" or similarly named menu. Look for "Add new item" or something similar.

- Or "File" "New Item" or something similar.


If all else fails, these files are all just text files, so you can create the file in notepad or <insert plain text editor here> and save it as "whatever.h" and then just add it to your Borland project.
Ok. I right clicked on my screen, clicked on Open Source/Header file, then selected text. I then saved it as the .h that the lesson says to.

I get these errors when I try to run.

1
2
3
[Linker Error] Unresolved external '__InitVCL' referenced from C:\PROGRAM FILES (X86)\BORLAND\CBUILDER6\LIB\CP32MTI.LIB|crtlvcl
[Linker Error] Unresolved external '__ExitVCL' referenced from C:\PROGRAM FILES (X86)\BORLAND\CBUILDER6\LIB\CP32MTI.LIB|crtlvcl
[Linker Error] Unresolved external '_main' referenced from C:\PROGRAM FILES (X86)\BORLAND\CBUILDER6\LIB\C0X32.OBJ


here is my cpp code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//---------------------------------------------------------------------------

#include <clx.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#pragma hdrstop
#include <structur.h>
void displayRecord(int, mailingListRecord m1Rec);

//---------------------------------------------------------------------------

#pragma argsused
int main(int, char**)
{
    //
    // create an array of mailingListRecord structures
    //
    mailingListRecord listArray[3]
    cout << endl;
    int index = 0;
    // get three records
    //
    do
        {
        cout << "First Name: ";
        cin.getline(listArray[index].firstname,
            sizeof(listArray[index].firstname) - 1);
        cout << "Last Name: ";
        cin.getline(listArray[index].lastname,
            sizeof(listArray[index].lastname) - 1);
        cout << "Address: ";
        cin.getline(listArray[index].address,
            sizeof(listArray[index].address) - 1);
        cout << "City: ";
        cin.getline(listArray[index].city,
            sizeof(listArray[index].city) - 1);
        cout << "State: ";
        cin.getline(listArray[index].state,
            sizeof(listArray[index].state) - 1);
        char buff[10];
        cout << "Zip: ";
        cin.getline(buff, sizeof(buff) -1);
        listArray[index].zip = atol(buff);
        index++;
        cout << endl;
        }
    while (index < 3);
    //
    // clear the screen
    //
    clrscr();
    //
    // display the three records
    //
    for (int i=0;i<3;i++)
        {
        displayRecord(i, listArray[i]);
        }
    //
    // ask the user to choose a record
    //
    cout << "Choose a record: ";
    char rec;
    //
    // be sure only 1, 2, or 3 was selected
    //
    do
        {
        rec = getch();
        rec -= 49;
        }
    while (rec < 0 || rec > 2);
    //
    // assign the selected record to a temporary variable
    //
    mailingListRecord temp = listArray[rec];
    clrscr();
    cout << endl;
    //
    // display the selected record
    //
    displayRecord(rec, temp);
    getch();
    return 0;
}
void displayRecord(int num, mailingListRecord mlRec)
{
    cout << "Record " << num + 1 << ":" << endl;
    cout << "Name:       " << mlRec.firstName << "  ";
    cout << mlRec.lastName;
    cout << endl;
    cout << "Address:   " << mlRec.address;
    cout << endl << "          ";
    cout << mlRec.city << ", ";
    cout << mlRec.state << "    ";
    cout << mlRec.zip;
    cout << endl << endl;
}
//--------------------------------------------------------------------------- 


and my STRUCTUR.H code

1
2
3
4
5
6
7
8
9
10
11
12
#ifndef _STRUCTUR.H
#define _STRUCTUR.H
struct mailingListRecord
{
    char firstName[20];
    char lastName[20];
    char address[50];
    char city[20];
    char state[5];
    int zip;
};
#endif 


-BHill
I fixed the missing semicolon on line 19. Not that that seems to be part of my problem.

-BHill
I wasnt sure if the #include was case sensitive, so I capitalized all letters, and still the same errors.

-BHill
To include your own files, use " " instead of < >

So, #include "Structure.h", not <structure.h>. And probably case sensitive too. Or not, but it's a good idea to do it anyway.
Ok, fixed that(i misread the book while typing, my bad), thank you. I still have the same errors. Do they need to be in the same folder? I would think they would. It seems to me that i need to do something so that the maillist.cpp has a path to find STRUCTUR.H file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//---------------------------------------------------------------------------

#include <clx.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#pragma hdrstop
#include "STRUCTUR.H"
void displayRecord(int, mailingListRecord m1Rec);

//---------------------------------------------------------------------------

#pragma argsused
int main(int, char**)
{
    //
    // create an array of mailingListRecord structures
    //
    mailingListRecord listArray[3];
    cout << endl;
    int index = 0;
    // get three records
    //
    do
        {
        cout << "First Name: ";
        cin.getline(listArray[index].firstname,
            sizeof(listArray[index].firstname) - 1);
        cout << "Last Name: ";
        cin.getline(listArray[index].lastname,
            sizeof(listArray[index].lastname) - 1);
        cout << "Address: ";
        cin.getline(listArray[index].address,
            sizeof(listArray[index].address) - 1);
        cout << "City: ";
        cin.getline(listArray[index].city,
            sizeof(listArray[index].city) - 1);
        cout << "State: ";
        cin.getline(listArray[index].state,
            sizeof(listArray[index].state) - 1);
        char buff[10];
        cout << "Zip: ";
        cin.getline(buff, sizeof(buff) -1);
        listArray[index].zip = atol(buff);
        index++;
        cout << endl;
        }
    while (index < 3);
    //
    // clear the screen
    //
    clrscr();
    //
    // display the three records
    //
    for (int i=0;i<3;i++)
        {
        displayRecord(i, listArray[i]);
        }
    //
    // ask the user to choose a record
    //
    cout << "Choose a record: ";
    char rec;
    //
    // be sure only 1, 2, or 3 was selected
    //
    do
        {
        rec = getch();
        rec -= 49;
        }
    while (rec < 0 || rec > 2);
    //
    // assign the selected record to a temporary variable
    //
    mailingListRecord temp = listArray[rec];
    clrscr();
    cout << endl;
    //
    // display the selected record
    //
    displayRecord(rec, temp);
    getch();
    return 0;
}
void displayRecord(int num, mailingListRecord mlRec)
{
    cout << "Record " << num + 1 << ":" << endl;
    cout << "Name:       " << mlRec.firstName << "  ";
    cout << mlRec.lastName;
    cout << endl;
    cout << "Address:   " << mlRec.address;
    cout << endl << "          ";
    cout << mlRec.city << ", ";
    cout << mlRec.state << "    ";
    cout << mlRec.zip;
    cout << endl << endl;
}
//--------------------------------------------------------------------------- 


-BHill
I put both in the same folder(the default folder that STRUCTUR.H went into. Still have these errors(I believe the errors are the same though I havent checked word for word.).

1
2
3
4
[Linker Error] Unresolved external '__InitVCL' referenced from C:\PROGRAM FILES (X86)\BORLAND\CBUILDER6\LIB\CP32MTI.LIB|crtlvcl
[Linker Error] Unresolved external '__ExitVCL' referenced from C:\PROGRAM FILES (X86)\BORLAND\CBUILDER6\LIB\CP32MTI.LIB|crtlvcl
[Linker Error] Unresolved external '_main' referenced from C:\PROGRAM FILES (X86)\BORLAND\CBUILDER6\LIB\C0X32.OBJ


-BHill
I have been googling, and still cant seem to find out what I am missing. Am I on the wrong path in thinking that the 'Linker Error' means that I have not done something to let both files know they are related?

-BHill
as per the advice of a friend, I started over, and pasted the header file into my cpp file. and recompiled.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//---------------------------------------------------------------------------

#include <clx.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#pragma hdrstop

#ifndef _STRUCTUR.H
#define _STRUCTUR.H
struct mailingListRecord
{
    char firstName[20];
    char lastName[20];
    char address[50];
    char city[20];
    char state[5];
    int zip;
};
#endif

void displayRecord(int, mailingListRecord m1Rec);

//---------------------------------------------------------------------------

#pragma argsused
int main(int, char**)
{
    //
    // create an array of mailingListRecord structures
    //
    mailingListRecord listArray[3];
    cout << endl;
    int index = 0;
    // get three records
    //
    do
        {
        cout << "First Name: ";
        cin.getline(listArray[index].firstName,
            sizeof(listArray[index].firstName) - 1);
        cout << "Last Name: ";
        cin.getline(listArray[index].lastName,
            sizeof(listArray[index].lastName) - 1);
        cout << "Address: ";
        cin.getline(listArray[index].address,
            sizeof(listArray[index].address) - 1);
        cout << "City: ";
        cin.getline(listArray[index].city,
            sizeof(listArray[index].city) - 1);
        cout << "State: ";
        cin.getline(listArray[index].state,
            sizeof(listArray[index].state) - 1);
        char buff[10];
        cout << "Zip: ";
        cin.getline(buff, sizeof(buff) -1);
        listArray[index].zip = atol(buff);
        index++;
        cout << endl;
        }
    while (index < 3);
    //
    // clear the screen
    //
    clrscr();
    //
    // display the three records
    //
    for (int i=0;i<3;i++)
        {
        displayRecord(i, listArray[i]);
        }
    //
    // ask the user to choose a record
    //
    cout << "Choose a record: ";
    char rec;
    //
    // be sure only 1, 2, or 3 was selected
    //
    do
        {
        rec = getch();
        rec -= 49;
        }
    while (rec < 0 || rec > 2);     //
    //
    // assign the selected record to a temporary variable
    //
    mailingListRecord temp = listArray[rec];
    clrscr();
    cout << endl;
    //
    // display the selected record
    //
    displayRecord(rec, temp);
    getch();
    return 0;
}
void displayRecord(int num, mailingListRecord mlRec)
{
    cout << "Record " << num + 1 << ":" << endl;
    cout << "Name:       " << mlRec.firstName << "  ";
    cout << mlRec.lastName;
    cout << endl;
    cout << "Address:   " << mlRec.address;
    cout << endl << "          ";
    cout << mlRec.city << ", ";
    cout << mlRec.state << "    ";
    cout << mlRec.zip;
    cout << endl << endl;
}


it is compiling fine, executes ok but acts wildly. Sometimes it will fill in random data into record 2 and 3, sometimes just into record 3. I would post a copy of my result, but I cant seem to copy and paste from the console window.

-BHill
I am wondering if there is data in the buffer that needs to be removed?

-BHill
Now this is interesting. I decided to see what index was while I was entering records. So I made a couple changes

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//---------------------------------------------------------------------------

#include <clx.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#pragma hdrstop

#ifndef _STRUCTUR
#define _STRUCTUR
struct mailingListRecord
{
    char firstName[20];
    char lastName[20];
    char address[50];
    char city[20];
    char state[5];
    int zip;
};
#endif



void displayRecord(int, mailingListRecord m1Rec);

//---------------------------------------------------------------------------

#pragma argsused
int main(int, char**)
{
    //
    // create an array of mailingListRecord structures
    //
    mailingListRecord listArray[3];
    cout << endl;
    int index = 0;
    // get three records
    //
    do
        {
        cout << "First Name: ";
        cin.getline(listArray[index].firstName,
            sizeof(listArray[index].firstName) - 1);
        cout << "Last Name: ";
        cin.getline(listArray[index].lastName,
            sizeof(listArray[index].lastName) - 1);
        cout << "Address: ";
        cin.getline(listArray[index].address,
            sizeof(listArray[index].address) - 1);
        cout << "City: ";
        cin.getline(listArray[index].city,
            sizeof(listArray[index].city) - 1);
        cout << "State: ";
        cin.getline(listArray[index].state,
            sizeof(listArray[index].state) - 1);
        char buff[10];
        cout << "Zip: ";
        cin.getline(buff, sizeof(buff) -1);
        listArray[index].zip = atol(buff);
        index++;
          cout << index << endl;
        getch();          }
    while (index < 3);
    //
    // clear the screen
    //
    clrscr();
    //
    // display the three records
    //
    for (int i=0;i<3;i++)
        {
        displayRecord(i, listArray[i]);
        }
    //
    // ask the user to choose a record
    //
    cout << "Choose a record: ";
    char rec;
    //
    // be sure only 1, 2, or 3 was selected
    //
    do
        {
        rec = getch();
        rec -= 49;
        }
    while (rec < 0 || rec > 2);     //
    //
    // assign the selected record to a temporary variable
    //
    mailingListRecord temp = listArray[rec];
    clrscr();
    cout << endl;
    //
    // display the selected record
    //
    displayRecord(rec, temp);
    getch();
    return 0;
}
void displayRecord(int num, mailingListRecord mlRec)
{
    cout << "Record " << num + 1 << ":" << endl;
    cout << "Name:       " << mlRec.firstName << "  ";
    cout << mlRec.lastName;
    cout << endl;
    cout << "Address:   " << mlRec.address;
    cout << endl << "          ";
    cout << mlRec.city << ", ";
    cout << mlRec.state << "    ";
    cout << mlRec.zip;
    cout << endl << endl;
}


Not sure why, but adding the getch() seemed to make it work.

Anybody have any ideas? Especially on how I can make the header file and like the two?

-BHill
Last edited on
Err. It only worked correctly one time. When i recompiled and ran it again(the same code with no modifications), it went back to its bad behaviour. It will only let you enter in the first record, and when it comes to zipcode, it doesnt let me enter anything after that. when it comes to the point to display the records, the 2nd two records comes up with gibberish ascii.

-BHill
i tried adding an ostream::flush to it, and worked one time,,then other times still fills the other records with gibberish ascii. I hope I am providing enough information here and that I could attach an image of my output.

-BHill
OK, I changed things up and dumped the atoi code and it works. im treating zip as a char now.

defeats part of what i was supposed to learn, but its the only way i can get it to work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//---------------------------------------------------------------------------

#include <clx.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#pragma hdrstop

#ifndef _STRUCTUR
#define _STRUCTUR
struct mailingListRecord
{
    char firstName[20];
    char lastName[20];
    char address[50];
    char city[20];
    char state[10];
    char zip[10];
};
#endif



void displayRecord(int, mailingListRecord m1Rec);

//---------------------------------------------------------------------------

#pragma argsused
int main(int, char**)
{
    //
    // create an array of mailingListRecord structures
    //
    mailingListRecord listArray[3];
    cout << endl;
    int index = 0;

    // get three records
    //
    do
        {
        cout << "First Name: ";
        cin.getline(listArray[index].firstName,
            sizeof(listArray[index].firstName) - 1);
        cout << "Last Name: ";
        cin.getline(listArray[index].lastName,
            sizeof(listArray[index].lastName) - 1);
        cout << "Address: ";
        cin.getline(listArray[index].address,
            sizeof(listArray[index].address) - 1);
        cout << "City: ";
        cin.getline(listArray[index].city,
            sizeof(listArray[index].city) - 1);
        cout << "State: ";
        cin.getline(listArray[index].state,
            sizeof(listArray[index].state) - 1);
        cout << "Zip: ";
        cin.getline(listArray[index].zip,
            sizeof(listArray[index].zip) -1);
        index++;
        cout << endl;
        }
    while (index < 3);
    //
    // clear the screen
    //
    clrscr();
    //
    // display the three records
    //
    for (int i=0;i<3;i++)
        {
        displayRecord(i, listArray[i]);
        }
    //
    // ask the user to choose a record
    //
    cout << "Choose a record: ";
    char rec;
    //
    // be sure only 1, 2, or 3 was selected
    //
    do
        {
        rec = getch();
        rec -= 49;
        }
    while (rec < 0 || rec > 2);     //
    //
    // assign the selected record to a temporary variable
    //
    mailingListRecord temp = listArray[rec];
    clrscr();
    cout << endl;
    //
    // display the selected record
    //
    displayRecord(rec, temp);
    getch();
    return 0;
}
void displayRecord(int num, mailingListRecord mlRec)
{
    cout << "Record " << num + 1 << ":" << endl;
    cout << "Name:       " << mlRec.firstName << "  ";
    cout << mlRec.lastName;
    cout << endl;
    cout << "Address:   " << mlRec.address;
    cout << endl << "          ";
    cout << mlRec.city << ", ";
    cout << mlRec.state << "    ";
    cout << mlRec.zip;
    cout << endl << endl;
}


I feel I submitted this bitch. Anybody care to comment? I'll have to learn the atoi stuff another day I guess. Maybe its the version of C++ builder I am using?

-BHill
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//---------------------------------------------------------------------------

#include <clx.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#pragma hdrstop

#ifndef _STRUCTUR
#define _STRUCTUR
struct mailingListRecord
{
    char firstName[20];
    char lastName[20];
    char address[50];
    char city[20];
    char state[10];
    int zip;
};
#endif



void displayRecord(int, mailingListRecord m1Rec);

//---------------------------------------------------------------------------

#pragma argsused
int main(int, char**)
{
    //
    // create an array of mailingListRecord structures
    //
    mailingListRecord listArray[3];
    cout << endl;
    int index = 0;

    // get three records
    //
    do
        {
        cout << "First Name: ";
        cin.getline(listArray[index].firstName,
            sizeof(listArray[index].firstName) - 1);
        cout << "Last Name: ";
        cin.getline(listArray[index].lastName,
            sizeof(listArray[index].lastName) - 1);
        cout << "Address: ";
        cin.getline(listArray[index].address,
            sizeof(listArray[index].address) - 1);
        cout << "City: ";
        cin.getline(listArray[index].city,
            sizeof(listArray[index].city) - 1);
        cout << "State: ";
        cin.getline(listArray[index].state,
            sizeof(listArray[index].state) - 1);
        char buff[10];
        cout << "Zip: ";
        cin.getline(buff, sizeof(buff) -1);
        listArray[index].zip = atoi(buff);
        index++;
        cout << endl;
        }
    while (index < 3);
    //
    // clear the screen
    //
    clrscr();
    //
    // display the three records
    //
    for (int i=0;i<3;i++)
        {
        displayRecord(i, listArray[i]);
        }
    //
    // ask the user to choose a record
    //
    cout << "Choose a record: ";
    char rec;
    //
    // be sure only 1, 2, or 3 was selected
    //
    do
        {
        rec = getch();
        rec -= 49;
        }
    while (rec < 0 || rec > 2);     //
    //
    // assign the selected record to a temporary variable
    //
    mailingListRecord temp = listArray[rec];
    clrscr();
    cout << endl;
    //
    // display the selected record
    //
    displayRecord(rec, temp);
    getch();
    return 0;
}
void displayRecord(int num, mailingListRecord mlRec)
{
    cout << "Record " << num + 1 << ":" << endl;
    cout << "Name:       " << mlRec.firstName << "  ";
    cout << mlRec.lastName;
    cout << endl;
    cout << "Address:   " << mlRec.address;
    cout << endl << "          ";
    cout << mlRec.city << ", ";
    cout << mlRec.state << "    ";
    cout << mlRec.zip;
    cout << endl << endl;
}


Done!

-BHill
I'm glad the C++ community was able to be so much help to you.

Meerkat
Uh, yeah, Meerkat.

I was able to figure out how to make a header file. I guess I am in the dark ages with the compiler I am using being the lack of response. But! I did find an answer.

Under File>New>Other There is a icon for creating a header file. Again, if I could upload a picture here, I would display it.

I haven't seperated the header file from what I compiled earlier, but will tomorow and probably bore you people some more with my situations.

So as Disch mentioned, it was there, I just had to dig deeper. The strange thing is, though this is a book on Borland C++ builder, I am required to dig alot to get things to work. The pictures they show dont look like mine(of the window for where I am supposed to be), and the code often takes alot of altering.

Am I really using something that outdated? Do I have the wrong book? The year of the software release and the book are only a year apart. Maybe I haven't smoked enough crack. Either way, it is frustrating.

-BHill
To be honest I'm really not too sure. I've never used it myself and can't say I know much about it. And yea make sure to ask if you have any trouble. People on this forum are normally a lot more involved than they seem to be on this topic. Glad you got it working though.

Meerkat
I figured it was because I didnt shower yesterday :( .

-BHill
Topic archived. No new replies allowed.