creating an array of structures

each struct created must hold the information (vendor name, category, desription, etc) for up to 20 booths at an event and write em to a file. i need to be able to do this for each of the three days. my question is how to go about writing the array of structures. i have the structs all made i just dont get how to save it for each seperate day

heres my code so far

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
#include <iostream>
#include <cstring>
#include <cctype>
#include <fstream>
#include <string>

using namespace std;


struct booth
{
   char *vendorName;
   char *category;
   char *description;
   char *email;
};

 struct guests
{
   char *guestName;
   char *accomplishemnt;
};
 struct node
{
   booth data;
   node *next;
};









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 "main.h"
using namespace std;

void GetVendor (booth *booth_ptr);
void GetCategory (booth *booth_ptr);

int main()
{
        ifstream fin;
        ofstream fout;
        char again('Y');
        booth booth_dat;
        booth *structPointer = new booth[3];

        while (again == 'Y' || again == 'y')
        {

                GetVendor ( &booth_dat );
                GetCategory ( &booth_dat );

                cout << "Would you like to run again?(y/n) " << endl;
                cin >> again;
                cin.ignore(100, '\n');
        }

        return 0;
}

void GetVendor (booth *booth_ptr)
{
        ofstream myfile;
        char temp[100];
        myfile.open("booth.txt", ios::app);
        char again('Y');
        int i(0);
        if (myfile.is_open())
        {
                while (again == 'y' || again == 'Y' && i < 20)
                {
                        cout << "Please enter Vendor name: " << endl;
                        cin.getline (temp, 100);
                        cin.ignore(100, '\n');

                        booth_ptr->vendorName = new char[strlen(temp) + 1];
                        strcpy( booth_ptr->vendorName, temp);

                        myfile << booth_ptr->vendorName;
                        myfile.close();
                        i++;

                        cout << "Would you like to enter another vendor?(y/n): " << endl;
                        cin >> again;
                }
void GetCategory ( booth *booth_ptr )
{
        int i(0);
        ofstream myfile;
        char temp[100];
        char again('Y');
        myfile.open ("booth.txt", ios::app);

        if (myfile.is_open())
        {
                while (again == 'y' || again == 'Y' && i < 20)
                {
                        cout << "please enter the catagory of your booth: " << endl;
                        cin.getline(temp, 100);
                        cin.ignore(100, '\n');

                        booth_ptr->category = new char[strlen (temp) + 1];
                        strcpy ( booth_ptr->category, temp);

                        myfile << booth_ptr->category;
                        myfile.close();
                        i++;

                        cout << "Would you like to enter another vendor?(y/n): " << endl;
                        cin >> again;

        }


void GetDescription ( booth *booth_ptr )
{
        int i(0);
        ofstream myfile;
        char temp[1000];
        char again('Y');
        myfile.open ("booth.txt", ios::app);

        if (myfile.is_open())
        {
                while (again == 'y' || again == 'Y' && i < 20)
                {
                        cout << "Please provide a description for your booth: " << endl;
                        cin.getline(temp, 1000);
                        cin.ignore(1000, '/n');

                        booth_ptr -> description = new char[strlen (temp) + 1];
                        strcpy ( booth_ptr -> description, temp);

                        myfile << booth_ptr -> description;
                        myfile.close();
                        i++;

                        cout << "Would you like to enter another vendor?(y/n): " << endl;
                        cin >> again;
                }
        }
}




}
You seem to be nesting some of your functions and there is not enough matching brackets.


...i just dont get how to save it for each seperate day


Do you mean save all the information for separate days into a file without overwriting the file's original content?
sort of. im using ios::app to make sure to not overwrite the file.
so im supposed to be scheduling booths for a 3 day event. and each day is different. im trying to create an array of my struct so that each element of the array represents a different day
there is not enough matching brackets.
http://www.hqew.net
Topic archived. No new replies allowed.