help needed with writing to a file

Feb 26, 2013 at 12:14am
so im trying to read in the name of a vendor into an array of structures. and write the name into a file. doing this gets me an error i haven't seen before and searching for it online has proven very unfruitful. any help would be awesome!
heres my code so far

the .h
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
#include <iostream>
#include <cstring>
#include <cctype>
#include <fstream>


using namespace std;


 struct booth
{
   char *vendorName;
   char *category;
   char *description;
   char *email;
   char temp[100];
};
 struct guests
{
   char *guestName;
   char *accomplishemnt;
};
 struct node
{
   booth data;
   node *next;
};


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

void GetVendor (booth *vendorName);
void GetCategory (booth *category);

int main()
{
  ifstream fin;
  ofstream fout;
  char again('Y');
  booth *vendorName = NULL;
  booth *category = NULL;

  while (again == 'Y' || again == 'y')
 {
    GetVendor ( vendorName );
    GetCategory ( category );

    cout << "Would you like to run again?(y/n) " << endl;
    cin >> again;
 }
    return 0;
}

 void GetVendor (booth *vendorName)
{
  ofstream myfile;
  booth temp[100];
  myfile.open("booth.txt", ios::app);

  if (myfile)
  {
   cout << "Please enter Vendor name: " << endl;
   cin.get (temp, 100, '\n');
   cin.ignore(100, '\n');

   *vendorName = new booth[strlen(temp) + 1];
   strcpy( *vendorName, temp);

    myfile << *vendorName;
    myfile.close();
  }

  delete [] vendorName;
}
void GetCategory ( booth  *category )
{
  ifstream fin;
  booth temp[100];
  file.open ("booth.txt", ios::app);
 if (fin)
 (
   cout << "please enter the catagory of your booth: " << endl;
   cin.get (temp, 100, '\n');
   cin.ignore(100, '\n');

   category = new booth[strlen(temp) + 1];
   strcpy ( category, temp );
}

Feb 26, 2013 at 12:25am
Is there a reason you're not using std::string for strings (instead of char*)?
Feb 26, 2013 at 12:41am
no, im fairly new to programming and didnt know that i should
Feb 26, 2013 at 3:00am
closed account (Dy7SLyTq)
whats your error? and why do u have an i/o file stream in main if you dont use it?
Feb 26, 2013 at 3:16am
Yea, need error to give us clues where it's happening.
Feb 26, 2013 at 6:43am
my error was with my struct and not creating the struct variable. i solved it thankfully
Topic archived. No new replies allowed.